2011-09-08 92 views
0

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

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

在你这样做之前。你能解释你为什么要这么做吗? – Layke

+0

Becouse用新值更新jsonStore之后,我需要将它们与旧值进行比较 – nath

+0

然后你做错了。看到我的答案。 – Layke

回答

1

根据上面提出的意见。您正在尝试将值复制到新的商店,原因在于能够检测哪些值已更改,然后单独保存它们,而无需发送整个商店。

这种方法是完全错误的。

Dojo有isDirty(),并为您提供revert()商店的能力回到它的原始值。它知道哪些值已经改变,您不需要这样做。

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

确保你从这里读到的一切:http://docs.dojocampus.org/dojo/data/ItemFileWriteStore#id8

你想要做的就是创建自己的_saveCustom方法,您将覆盖你的店有哪些,然后当你保存时,你将能够看到哪些值已经改变。

点击页面最底部的演示。它显示了你如何使用_saveCustom