Dojo - error trying remove and add item to store (assertion failed in ItemFileWriteStore)

4.1k views Asked by At

I have store (and grid which displays its content), users could remove and add item but unfortunately one item after deleting could not be again added. I figure out problem is same id which was previously in store.

I use Dojo 1.6.

In firebug console I got:

Error: assertion failed in ItemFileWriteStore

Here is demo on jsFiddle: http://jsfiddle.net/MBBnE/

and here code:

dojo.require("dojo.data.ItemFileWriteStore");

dojo.addOnLoad(function() {

    var d = {
        items: [
            {
            id: 23,
            x: 2},
            ],
        identifier: "id",
    };

    var _store = new dojo.data.ItemFileWriteStore({
        data: d,
    });

    var it = null;

    _store.fetch({
        query: {
            id: "23*"
        },
        onItem: function(i) {
            it = i;
        }
    })

    _store.deleteItem(it);

    console.info(it);

    _store.newItem({id: 23, x: 3});
});
3

There are 3 answers

1
xangxiong On BEST ANSWER

Hopefully I didn't misunderstand your question, but when you remove an item from a store if you want to re-add another item with the same id, you should save the store then re-add the item. Saving the store will clear all dirty items and allow the id to be reuse.

0
IProblemFactory On

Finally I did a little workaround - create new store and copy all items to it:

    oldStore.fetch({
        onItem: function(it){

            var newItem = {
                id: it.id[0],
                valueX: it.valueX[0],
                (...)
            };

            newStore.newItem(newItem);
        }
    });
1
Mithlesh Kumar On

When you insert same value in Itemfilewritestore it will give you error 'assertion failed in ItemFileWriteStore' To overcome this problem insert new or unique value in ItemFileWriteStore

_store.newItem({id: 24, x: 3});

I hope this will help you.