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

dojo, dojo-1.6, javascript

Solution

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.

Problem

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

Original source