简体   繁体   English

Dojo - 尝试删除并添加项目到存储时出错(在ItemFileWriteStore中断言失败)

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

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. 我发现问题是以前在店里的同一个id。

I use Dojo 1.6. 我使用Dojo 1.6。

In firebug console I got: 在firebug控制台中,我得到了:

Error: assertion failed in ItemFileWriteStore

Here is demo on jsFiddle: http://jsfiddle.net/MBBnE/ 这是关于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});
});

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. 希望我没有误解你的问题,但是当你想要重新添加具有相同id的另一个项目时从商店中删除项目时,你应该保存商店然后重新添加项目。 Saving the store will clear all dirty items and allow the id to be reuse. 保存商店将清除所有脏项并允许重用ID。

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 当您在Itemfilewritestore中插入相同的值时,它将为您提供错误'在ItemFileWriteStore中断言失败'要解决此问题,请在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);
        }
    });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM