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);
}
}
}
}
在你這樣做之前。你能解釋你爲什麼要這麼做嗎? – Layke
Becouse用新值更新jsonStore之後,我需要將它們與舊值進行比較 – nath
然後你做錯了。看到我的答案。 – Layke