您需要构建一个JSONStore文档数组,并将其传递给
replace
应用程序编程接口。例如:
.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实现期望代码被串行调用。等待一个操作完成后再调用下一个操作。
当您拨打
代替
无需等待多次,您就可以并行而不是串行地调用API。这在生产环境(即Android、iOS、WP8和W8)中不应成为问题。