【问题标题】:How save multiple values JSONStore如何保存多个值 JSONStore
【发布时间】:2014-10-26 10:13:00
【问题描述】:

我需要替换 IBM Worklight 的 JSONStore 中的多个值。 以这种方式只保存第一个值。为什么?

 .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);
    }
  })

【问题讨论】:

    标签: save ibm-mobilefirst savechanges jsonstore multivalue


    【解决方案1】:

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

    .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 的 JavaScript 实现中,如果是这种情况,答案在文档 here 中。 JSONStore 的 JavaScript 实现期望代码被串行调用。在调用下一个操作之前等待一个操作完成。 当您多次调用replace 而不等待时,您是在并行调用 API,而不是串行调用。这在生产环境(即 Android、iOS、WP8 和 W8)中应该不是问题。

    【讨论】:

      猜你喜欢
      • 2014-11-20
      • 2012-02-21
      • 1970-01-01
      • 1970-01-01
      • 2017-12-29
      • 1970-01-01
      • 2020-08-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多