4

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});
});
IProblemFactory
  • 9,551
  • 8
  • 50
  • 66

3 Answers3

6

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.

xangxiong
  • 596
  • 4
  • 9
  • 2
    thanks, I've been using SO for a while on and off and haven't had the time to contribute. Finally found time to give back. – xangxiong Dec 06 '12 at 16:14
1

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.

Mithlesh Kumar
  • 748
  • 7
  • 16
0

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);
        }
    });
IProblemFactory
  • 9,551
  • 8
  • 50
  • 66