如何在Worklight 6.1中正确初始化JSON存储 [英] How to properly initialize the JSON store in Worklight 6.1

查看:114
本文介绍了如何在Worklight 6.1中正确初始化JSON存储的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试初始化IBM Worklight JSON存储,如下所示:

I am attempting to initalize the IBM Worklight JSON store as below:

//JSONStore jsonStoreCollection metadata
var jsonStoreCollection = {};

//JSONStore jsonStoreCollection metadata
var COLLECTION_NAME = 'people';

function wlCommonInit(){


    // Create empty options to pass to
    // the WL.JSONStore.init function
    var options = {};

    //Define the collection and list the search fields
    jsonStoreCollection[COLLECTION_NAME] = {
        searchFields : {name: 'string'},
    };


    //Initialize the JSON store collection
    WL.JSONStore.init(jsonStoreCollection, options)
    .then(function () {
        console.log("Successfully Initialized the JSON store");
    })
    .fail(function (errorObject) {
        console.log("JSON store init failed :( ");
    });

}

但是当我在我的机器人中运行它时模拟器logcat给我JSON store init failed消息。并出现以下错误:

But when I run this in my android emulator the logcat gives me the "JSON store init failed" message. And the following error:

[wl.jsonstore {"src":"initCollection", "err":-2,"msg":"PROVISION_TABLE_SEARCH_FIELDS_MISMATCH","col":"token","usr":"jsonstore","doc":{},"res":{}}

这个实现似乎非常符合文档中的概述,但我无法理解初始化。

This implementation seems to be very much what is outlined in the documentation, however I cannot get it to initialize.

有谁能告诉我这里我做错了什么?

Can anyone tell me what I am doing wrong here?

推荐答案

错误代码的文档是<小时ef =http://pic.dhe.ibm.com/infocenter/wrklight/v6r1m0/index.jsp?topic=%2Fcom.ibm.worklight.dev.doc%2Fdevref%2Fr_jsonstore_errorcodes.html\"rel =nofollow>这里。


-2 PROVISION_TABLE_SEARCH_FIELDS_MISMATCH

-2 PROVISION_TABLE_SEARCH_FIELDS_MISMATCH

搜索字段不是动态。在使用新搜索字段调用init方法之前,如果不调用
中的destroy方法或者WL.JSONStore
类中的removeCollection方法,则无法更改搜索字段。如果更改搜索字段的名称或类型,则会发生
错误。
例如:{key:'string'}到{key:'number'}或{myKey:'string'}
到{theKey:'string'}。

Search fields are not dynamic. It is not possible to change search fields without calling the destroy method or the removeCollection method in the WL.JSONStore class before calling the init method with the new search fields. This error can occur if you change the name or type of the search field. For example: {key: 'string'} to {key: 'number'} or {myKey: 'string'} to {theKey: 'string'}.

无需卸载应用程序,只需按照文档处理并通过调用 removeCollection 或<来处理该错误情况code>破坏。例如:

No need to uninstall the application, just follow the documentation and handle that error case by calling removeCollection or destroy. For example:

WL.JSONStore.init(...)
.then(function () {
  //init was successful
})
.fail(function (error) {
  //check for -2
  //call removeCollection or destroy
  //re-init with new search fields
});

您始终可以提交功能请求以简化此操作。

You can always submit a feature request to make this easier.

这篇关于如何在Worklight 6.1中正确初始化JSON存储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆