0

嗨,有人可以告诉我如何在 dojo 中将一个数据存储复制到另一个。我按照以下方式尝试了它,但它不起作用。在这里,我尝试将数据从 jsonStore 复制到 newGridStore。

jsonStore.fetch({query:{} , onComplete: onComplete});

var onComplete = function (items, request) {
    newGridStore = null;
    newGridStore =  new dojo.data.ItemFileWriteStore({
        data : {}
    });
    if (items && items.length > 0) {
    var i;
    for (i = 0; i < items.length; i++) {
        var item = items[i];
        var attributes = jsonStore.getAttributes(item);
        if (attributes && attributes.length > 0) {
            var j;
            for (j = 0; j < attributes.length; j++) {
                var newItem = {};
                var values = jsonStore.getValues(item, attributes[j]);
                if (values) {
                    if (values.length > 1) {
                    // Create a copy.
                    newItem[attributes[j]] = values.slice(0, values.length);
                    } else {
                        newItem[attributes[j]] = values[0];
                    }
                }
            }
        newGridStore.newItem(newItem);
        }
        }
    }
}
4

1 回答 1

1

根据上面提出的意见。您尝试将值复制到新存储区的唯一原因是能够检测哪些值发生了更改,然后单独保存它们,而无需发送整个存储区。

这种做法是完全错误的。

Dojo 拥有isDirty()并为您提供了revert()将存储恢复到其原始值的能力。它知道哪些值发生了变化,您不需要这样做。

看看这里的沼泽标准 IFWS:http: //docs.dojocampus.org/dojo/data/ItemFileWriteStore

确保您从这里阅读了所有内容:http: //docs.dojocampus.org/dojo/data/ItemFileWriteStore#id8

您要做的是创建自己的_saveCustom方法,您将使用该方法覆盖您的商店,然后在保存时,您将能够看到哪些值已更改。

单击页面最底部的演示。它向您展示了如何使用 _saveCustom 进行操作

于 2011-09-08T11:04:27.123 回答