【问题标题】:How to get an already created JSONStore in Mobilefirst如何在 Mobilefirst 中获取已创建的 JSONStore
【发布时间】:2016-08-12 04:10:25
【问题描述】:

我正在尝试在 Mobilefirst 7.0 混合应用程序中创建 JSONStore。我遇到的问题是能够在应用程序的后续运行中检测到 JSONStore 已经存在。文档说您必须在调用 WL.JSONStore.get(...) 之前调用 WL.JSONStore.init(...)。

所以问题是,在应用程序的后续运行(意味着应用程序第一次运行并成功创建 JSONStore)并且这是一次新运行时,检查 JSONStore 是否已存在的正确方法是什么?

如果我必须再次调用 init,我该如何在不清除其中的内容的情况下这样做?

我目前正在使用这个sn-p的代码来检测...

function checkJSONStore() {

alert("In checkJSONStore");

var collectionName;

try {
    // Check to see if JSONStore exists...
    collectionName = WL.JSONStore.get('appStore');

} catch (e) {
    // TODO: handle exception
    alert("checkJSONStore: Exception = " + e.message);
}

alert("Returning from checkJSONStore: " + collectionName);

return collectionName;
}

这是创建商店的代码......它运行成功。

function initJSONStore() {

console.log("In initJSONStore:");

var collectionName = "appStore";

var Data = {
 item: 'newinstall',
 value: 1
};

var JSONStoreCollections = {};
JSONStoreCollections[collectionName] = {};
JSONStoreCollections[collectionName].searchFields = {item: 'string'};

try {

    console.log("Destroy any collections before we start");

    WL.JSONStore.destroy().then(function () {
        //handle success
        console.log("initJSONStore: JSONStore destroy success");
    })
    .fail(function (error) {
        //handle failure
        console.log("initJSONStore: JSONStore destroy failure: " + error);
    });

    console.log("Calling WL.JSONStore.init");

    WL.JSONStore.init(JSONStoreCollections).then(function () {

        console.log("initJSONStore: JSONStore init success");

        WL.JSONStore.get('appStore').add(Data).then(function () {

            console.log("initJSONStore: JSONStore add success");

        }).fail(function (error) {

            console.log("initJSONStore: JSONStore add failure: " + error);
        });

    }).fail(function (error) {

        console.log("initJSONStore: JSONStore init failure");
    });
} catch (e) {
    // TODO: handle exception
    //console.log("initJSONStore: Exception = " + e.message);
    alert("initJSONStore: Exception = " + e.message);
}
console.log("Exiting initJSONStore:");
 }

【问题讨论】:

    标签: ibm-mobilefirst jsonstore


    【解决方案1】:

    再次调用.init 不会清除您已经创建的收藏。只有调用.destroy,已经创建的集合才会被销毁......等下一个初始化它会被(重新)创建。

    【讨论】:

    • 那么使用 init 和 get 检查它的语法是什么?
    • 这更像是一个自定义实现来检查它。您可以在以下文件中看到一个示例。见onlineAuthenticationSuccess()函数:github.com/MobileFirst-Platform-Developer-Center/…
    • Idan,您提到“等在下一次初始化时,它将被(重新)创建。”......不是持久集合的点,即对象被持久化,我可以只是拿来?如果我每次都必须重新创建它......那么它并没有真正持久......也许这是我的错误假设?
    • 它没有被重新创建。如果它存在,它正在被使用。它是 .destroyed() 它将被重新创建(空)。
    猜你喜欢
    • 2016-05-21
    • 2016-07-19
    • 2015-09-04
    • 2015-09-24
    • 2017-08-17
    • 2023-03-05
    • 2015-06-04
    • 2015-10-06
    • 2016-04-27
    相关资源
    最近更新 更多