0

我正在使用dojo 1.6 版本。我的理解是: if store._saveEverything = saveCompleteCallback; 定义了,那么只有调用store.save()时才会调用回调函数saveCompleteCallback?

我是否需要使用回调函数 saveCompleteCallback( saveSuccess , saveFail , storeData){}中定义的第一个第二个参数?因为我只知道调用 store.save({onComplete: saveSuccess , onError: saveFail }) 时需要使用它们?

4

1 回答 1

0

首先,当我需要将 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);
        }
    );
}
于 2013-06-17T17:38:53.247 回答