Daten einer JSONStore-Sammlung abrufen

improve this page | report issue

React-Native-Entwicklungsumgebung einrichten

Führen Sie die Anweisungen von der React-Native-Seite Gettings Started aus, um Ihre Maschine für die React-Native-Entwicklung einzurichten.

JSONStore-SDK zu Ihrer React-Native-App hinzufügen

Das JSONStore-SDK für React Native ist als React-Native-Module von npm verfügbar.

Erste Schritte mit einem neuen React-Native-Projekt

  1. Erstellen Sie ein neues React-Native-Projekt.
     react-native init MyReactApp
    
  2. Fügen Sie das MobileFirst-SDK zu Ihrer App hinzu.
     cd MyReactApp
     npm install react-native-ibm-mobilefirst-jsonstore --save
    
  3. Verlinken Sie alle nativen Abhängigkeiten mit Ihrer App.
    react-native link
    

Daten einer JSONStore-Sammlung abrufen

In Ihrer Datei App.js müssen Sie die folgenden Pakete importieren:

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

Das Abrufen von Daten einer JSONStore-Sammlung erfolgt in zwei Schritten:

  1. Sie müssen eine Sammlung öffnen, um mit ihr interagieren zu können.
     WLJsonStore.openCollections(['favourites']).then(data => { console.log(data); }).catch(err =>{ console.log(err); });
    
  2. Nachdem Sie eine Sammlung geöffnet haben, können Sie mit der folgenden API alle Dokumente der Sammlung abrufen.
     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 27, 2020