JSONStore 콜렉션에서 데이터 페치

improve this page | report issue

React Native 개발 환경 설정

React Native 개발을 위해 사용하는 시스템을 설정하려면 React Native 시작하기 페이지에서 제공되는 지시사항을 따르십시오.

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 콜렉션에서 데이터를 페치합니다.

  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 May 13, 2020