JSONStore コレクションからのデータの取り出し

improve this page | report issue

React Native 開発環境のセットアップ

React Native 開発用にご使用のマシンをセットアップするには、React Native の『Gettings Started』ページに記載されている手順に従います。

React Native アプリケーションへの JSONStore SDK の追加

React Native 用の JSONStore SDK は、npm から 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 コレクションからデータを取り出すためのステップは以下の 2 つです。

  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 February 28, 2020