IBM MobileFirst 6.3 JSONStore 移除 JS 中的问题
IBM MobileFirst 6.3 JSONStore remove issue in JS
我正在使用
WL.JSONStore.get(collectionName).remove(doc)
在我的代码中,有时它不会删除文档,甚至不会将它们标记为已删除。我可能做错了什么?
顺便说一下,这个:
WL.JSONStore.get(collectionName).clear()
工作正常。
更新:
好的,这是一些代码,它是我浏览器中的结果。
var collectionName = 'samplecollection';
var data = [{"name":"Jimbo"},{"name":"Patrick"},{"name":"Alex"},{"name":"Sam"},{"name":"Charlie"},{"name":"Donnie"}];
WL.JSONStore.init({samplecollection:{}}).then(function() {
WL.JSONStore.get(collectionName).add(data).then(function(){
WL.JSONStore.get(collectionName).findAll().then(function(docs){
var promises = [];
docs.forEach(function(doc){
console.log(doc);
var promise = WL.JSONStore.get(collectionName).remove(doc);
promises.push(promise);
});
$.when.apply(null, promises).done(function() {
WL.JSONStore.get(collectionName).findAll().then(function(docs){
console.table(docs);
});
});
});
});
});
我希望 console.table 显示一个空数组。但它不是空的。它也没有所有保存的对象。所以我试图了解这里发生了什么。有什么想法吗?
根据我的经验,JSONStore for JS 不能很好地处理并行请求。您可以使用 async.js 之类的东西来创建串行请求。
我在这个博客中介绍了其中的一些内容 https://developer.ibm.com/mobilefirstplatform/2015/02/24/working-jsonstore-collections-join/
我正在使用
WL.JSONStore.get(collectionName).remove(doc)
在我的代码中,有时它不会删除文档,甚至不会将它们标记为已删除。我可能做错了什么? 顺便说一下,这个:
WL.JSONStore.get(collectionName).clear()
工作正常。
更新:
好的,这是一些代码,它是我浏览器中的结果。
var collectionName = 'samplecollection';
var data = [{"name":"Jimbo"},{"name":"Patrick"},{"name":"Alex"},{"name":"Sam"},{"name":"Charlie"},{"name":"Donnie"}];
WL.JSONStore.init({samplecollection:{}}).then(function() {
WL.JSONStore.get(collectionName).add(data).then(function(){
WL.JSONStore.get(collectionName).findAll().then(function(docs){
var promises = [];
docs.forEach(function(doc){
console.log(doc);
var promise = WL.JSONStore.get(collectionName).remove(doc);
promises.push(promise);
});
$.when.apply(null, promises).done(function() {
WL.JSONStore.get(collectionName).findAll().then(function(docs){
console.table(docs);
});
});
});
});
});
我希望 console.table 显示一个空数组。但它不是空的。它也没有所有保存的对象。所以我试图了解这里发生了什么。有什么想法吗?
根据我的经验,JSONStore for JS 不能很好地处理并行请求。您可以使用 async.js 之类的东西来创建串行请求。
我在这个博客中介绍了其中的一些内容 https://developer.ibm.com/mobilefirstplatform/2015/02/24/working-jsonstore-collections-join/