Dojo - an error is trying to delete and add an item for storage (approval failed in ItemFileWriteStore)

I have a repository (and a grid displaying its contents), users can delete and add an item, but, unfortunately, one item cannot be added again after deletion. I found out that the problem is the same identifier that was previously in the store.

I am using Dojo 1.6.

In the firebug console, I got:

Error: assertion failed in ItemFileWriteStore 

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

and here is the 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}); }); 
+4
source share
3 answers

I hope I didn’t get you wrong, but when you delete an item from the store, if you want to re-add another item with the same identifier, you must save the store and then add the item again. Saving the store will clear all dirty items and allow reuse of the identifier.

+6
source

When you insert the same value in an Itemfilewritestore, this will result in an error caused by an error in the ItemFileWriteStore 'To overcome this problem, insert a new or unique value in the ItemFileWriteStore

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

Hope this helps you.

+1
source

Finally, I made a small workaround - create a new store and copy it:

  oldStore.fetch({ onItem: function(it){ var newItem = { id: it.id[0], valueX: it.valueX[0], (...) }; newStore.newItem(newItem); } }); 
0
source

Source: https://habr.com/ru/post/1446952/


All Articles