简体   繁体   中英

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. 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. You could use something like async.js to create serial request.

I cover some of this in this blog https://developer.ibm.com/mobilefirstplatform/2015/02/24/working-jsonstore-collections-join/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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