开发者

cloning/copying a dojo data store

Hi can some one please tell me how to copy one data store to another in dojo. I tried it in following way but it doesn't work. Here I'm try to copy data from jsonStore to 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);
        }
        }
    }
}


Based on the comments asked above. You are trying to copy values to a new Store for the single reason to be able to detect which values have changes and then save them individually, without having to send the entire store.

This approach is totally wrong.

Dojo has isDirty() and offers you the ability to revert() a store back to it's original values. It knows which values have changed and you don't need to do this.

Take a look at the bog standard IFWS here: http://docs.dojocampus.org/dojo/data/ItemFileWriteStore

Make sure you read everything from here: http://docs.dojocampus.org/dojo/data/ItemFileWriteStore#id8

What you want to do is create your own _saveCustom method which you will override your store with, and then when you save, you will be able to see which values have changed.

Click on the demo at the very bottom of the page. It shows you EXACTLY how do to it using _saveCustom

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜