简体   繁体   English

Worklight WL.JSONStore替换文档失败

[英]Worklight WL.JSONStore Replace Doc failed

I have initialize a collection. 我已经初始化了一个集合。 In that i have a single doc which holds UserPreferences. 在那我有一个文档,其中包含UserPreferences。 I an trying to updated few fields of this doc. 我试图更新此文档的几个字段。 But fails with errorCallback. 但是由于errorCallback而失败。

var dataToUpdate = {
                                userPreferencesID:1,
                                firstname:'Test Name',
                                lastName: 'Test Name 2'};   
WL.JSONStore.get(tableName).replace(dataToUpdate).then(successCallback).fail(errorCallback);

If some forum i could see the syntax 如果有一些论坛,我可以看到语法

WL.JSONStore.get(tableName).replace(query, option).then(successCallback).fail(errorCallback);

Which one is correct. 哪一个是正确的。 I tried both, but failed to update the record. 我两者都尝试过,但未能更新记录。

IBM Worklight Version 6.1.0.2 IBM Worklight版本6.1.0.2

Thank in advance. 预先感谢。

The replace API takes a JSONStore document as the first parameter. replace API将JSONStore文档作为第一个参数。 For example: 例如:

{_id: 1, json: {userPreferencesID: 1, firstname: 'Test Name', lastName: 'Test Name 2'}}

Notice the _id and json keys. 注意_idjson键。 You're not passing a document as the first parameter. 您没有将文档作为第一个参数传递。

Here's the API documentation for the replace API in Worklight v6.1. 这是Worklight v6.1中替换API的API文档

You get JSONStore documents when you use, for example, the findAll API: 使用时会获取JSONStore文档,例如, findAll API:

WL.JSONStore.get('collection').findAll()
.then(function (jsonstoreDocuments) {
  // [{_id: 1, json: {name: 'carlitos', age: 99}}]
});

The example above presumes the JSONStore collection is not empty, if it's empty you'll get an empty array back (ie [] ). 上面的示例假定JSONStore集合不为空,如果为空,则将返回一个空数组(即[] )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM