最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin1浏览0评论

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: /

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

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/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});
});
Share Improve this question edited Dec 5, 2012 at 8:30 AbstractProblemFactory asked Nov 19, 2012 at 13:40 AbstractProblemFactoryAbstractProblemFactory 9,8118 gold badges52 silver badges67 bronze badges 3
  • 1 Dojo stores don't free the identifier after deletion. At least in 1.6. :( – undefined Commented Nov 19, 2012 at 13:43
  • I got 1.6! Have you some solution to that issue? – AbstractProblemFactory Commented Nov 19, 2012 at 13:44
  • Sadly, I don't. I ended up using a separate auto generated field for the identifier, when I found this "feature". – undefined Commented Nov 19, 2012 at 13:57
Add a ment  | 

3 Answers 3

Reset to default 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.

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

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

I hope this will help you.

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);
        }
    });
发布评论

评论列表(0)

  1. 暂无评论