首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何保存多个值JSONStore

如何保存多个值JSONStore
EN

Stack Overflow用户
提问于 2014-09-02 07:51:33
回答 1查看 183关注 0票数 0

我需要在的JSONStore中替换多个值。这样只保存了第一个值。为什么?

代码语言:javascript
复制
 .then(function() {                             
   for (var index = 0; index < elencoSpese.length; index++) {                                          
       var spesa = elencoSpese[index];                              
       var spesaReplace = {_id: spesa.id, json: spesa};                                 
       spesa.id_nota_spesa = idNotaSpesa;                               
       spesa.checked = true;                            
       WL.JSONStore.get(COLLECTION_NAME_SPESE).replace(spesaReplace);
    }
  })
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-09-02 13:38:40

您希望构建一个JSONStore文档数组并将其传递给replaceAPI。例如:

代码语言:javascript
复制
.then(function() {

    var replacementsArray = [];

    for (var index = 0; index < elencoSpese.length; index++) {
        var spesa = elencoSpese[index];
        var spesaReplace = {_id: spesa.id, json: spesa};
        spesa.id_nota_spesa = idNotaSpesa;
        spesa.checked = true;
        replacementsArray.push(spesaReplace);
    }

    return WL.JSONStore.get(COLLECTION_NAME_SPESE).replace(replacementsArray);

})
.then(function (numOfDocsReplaced) {
    // numOfDocsReplaced should equal elencoSpese.length
})

我假设这发生在JSONStore API的JSONStore实现中,如果是这样的话,答案是在文档这里中。JavaScript实现的JSONStore期望代码被串行调用。在调用下一个操作之前,等待操作完成。在不等待的情况下多次调用replace时,您将并行地调用API,而不是串行调用。这在生产环境中不应该是一个问题(即Android、iOS、WP8和W8)。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25618426

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档