简体   繁体   English

IBM MobileFirst 6.3 JSONStore除去JS中的问题

[英]IBM MobileFirst 6.3 JSONStore remove issue in JS

I'm using 我正在使用

WL.JSONStore.get(collectionName).remove(doc) 

in my code and sometimes it doesn't remove docs, not even mark them deleted. 在我的代码中,有时它不会删除文档,甚至不会将它们标记为已删除。 What can I possibly do wrong? 我可能会做错什么? By the way, this: 顺便说一句,这:

WL.JSONStore.get(collectionName).clear()

works fine. 工作正常。

UPDATE: 更新:

Ok, here some code, and it's result in my browser. 好的,这里有一些代码,它在我的浏览器中显示。

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

chrome中的代码结果

I expected console.table to display an empty array. 我希望console.table显示一个空数组。 But it's not empty. 但这不是空的。 It doesn't have all saved objects either. 它也没有所有保存的对象。 So I'm trying to understand what is going on here. 所以我试图了解这里发生了什么。 Any ideas? 有任何想法吗?

JSONStore for JS does not work well with parallel requests from my experience. 根据我的经验,JS的JSONStore不能很好地处理并行请求。 You could use something like async.js to create serial request. 您可以使用async.js之类的东西来创建串行请求。

I cover some of this in this blog https://developer.ibm.com/mobilefirstplatform/2015/02/24/working-jsonstore-collections-join/ 我在此博客中介绍了部分内容https://developer.ibm.com/mobilefirstplatform/2015/02/24/working-jsonstore-collections-join/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM