我需要在的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);
}
})发布于 2014-09-02 13:38:40
您希望构建一个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的JSONStore实现中,如果是这样的话,答案是在文档这里中。JavaScript实现的JSONStore期望代码被串行调用。在调用下一个操作之前,等待操作完成。在不等待的情况下多次调用replace时,您将并行地调用API,而不是串行调用。这在生产环境中不应该是一个问题(即Android、iOS、WP8和W8)。
https://stackoverflow.com/questions/25618426
复制相似问题