首先,当我需要将 dojox.data.dataGrid 的数据先 xhrPosted 然后 xhrGeted 时,我只使用 _saveEverything。
假设您定义: store._saveEverything = saveCompleteCallback;
我刚刚发现,包括 saveCompleteCallback(saveSuccess, saveFail, storeData) 的第一个和第二个参数是必要的,因为需要在 saveCompleteCallback() 中再次调用额外的 saveSuccess() 和 saveFail() 函数。例如
// 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);
}
);
}