从 JSONStore 集合中访存数据

improve this page | report issue


设置 React Native 开发环境

遵循 React Native 入门页面中提供的指示信息来设置您的机器进行 React Native 开发。

将 JSONStore SDK 添加到 React Native 应用程序

npm 中,JSONStore SDK for React Native 作为 React Native 模块提供。

开始使用新 React Native 项目

  1. 创建新 React Native 项目。
     react-native init MyReactApp
    
  2. 将 MobileFirst SDK 添加到您的应用程序。
     cd MyReactApp
     npm install react-native-ibm-mobilefirst-jsonstore --save
    
  3. 将所有本机依赖关系添加到您的应用程序。
    react-native link
    

从 JSONStore 集合中访存数据

在您的 App.js 内,必须导入以下包:

import { JsonStoreCollection, WLJsonStore } from 'react-native-ibm-mobilefirst-jsonstore';

从 JSONStore 集合中访存数据时需要执行两个步骤:

  1. 打开集合,打开集合使我们能够与之交互。
     WLJsonStore.openCollections(['favourites']).then(data => { console.log(data); }).catch(err =>{ console.log(err); });
    
  2. 从集合中访存数据:在您打开集合之后,可以使用以下 API 来访存所有文档。
     var favCollection = new JSONStoreCollection('favourites');
     favCollection.findAllDocuments()
     .then(data => {
     	console.log("Succesfully fetched all documents from collection!"));
     	console.log("Data: " + JSON.stringify(data));
     .catch(err => {
     	console.log("Error while fetching data from collection. Reason : " + err);
     });
    
Inclusive terminology note: The Mobile First Platform team is making changes to support the IBM® initiative to replace racially biased and other discriminatory language in our code and content with more inclusive language. While IBM values the use of inclusive language, terms that are outside of IBM's direct influence are sometimes required for the sake of maintaining user understanding. As other industry leaders join IBM in embracing the use of inclusive language, IBM will continue to update the documentation to reflect those changes.
Last modified on June 01, 2020