我正在使用dojo 1.6版本。我的理解是:if store._saveEverything = saveCompleteCallback;定义了,当调用store.save()时,回调函数saveCompleteCallback将被称为仅?
我是否需要使用回调函数saveCompleteCallback中定义的 1st 和 2nd params ( saveSuccess , saveFail ,storeData){}?因为我只知道在调用store.save时需要使用它们({onComplete: saveSuccess ,onError: saveFail })?
答案 0 :(得分:0)
首先,当我需要dojox.data.dataGrid的数据为xhrPosted然后xhrGeted时,我才使用_saveEverything。
假设你定义:store._saveEverything = saveCompleteCallback;
我刚才想到,包含saveCompleteCallback(saveSuccess,saveFail,storeData)的第1和第2个参数是必要的,因为需要在saveCompleteCallback()中再次调用额外的saveSuccess()和saveFail()函数。 e.g。
// When you wanna upload datagrid, you click upload button
Store.save({ onComplete : saveSuccess, onError : saveFail });
// Definition of saveCompleteCallback
function saveCompleteCallback(saveSuccess, saveFail, storeData) {
dojo.xhrpost(
url: posturl,
postData:storeData,
load: function(data) {
// saveSuccess() must be invoked here again,
// otherwise this function will not be called
saveSuccess();
}
);
}
function saveSuccess() {
dataGrid = dijit.byId('YOUR DATAGRID ID');
dojo.xhrGet(
url: geturl,
load: function(date){
// The reason that a new xhrGet is called is db data is updated
// So the dataGrid will have no value after xhrPost
var store = new dojo.data.ItemFileWriteStore({data: data});
store._saveEverything = saveEverything;
store.clearOnClose = true;
store.urlPreventCache = true;
dataGrid.setStore(store);
}
);
}