简体   繁体   中英

dojo dojo.data.ItemFileWriteStore slow…?

I've got some code that requests some data from a servlet, and renders it in a dojox.grid.DataGrid. This seems to be rather slow though! I'm stuck on how to make it faster. Can anyone help out?

I'm testing with

Dojo 1.34 FF & Chrome.

My code remove all items in the dojo.data.ItemFileWriteStore, then adds new ones that come back from a JSON request.

 //Define globla var for the WriteStore...
 var deltaInfo;
 var rawdataDeltaInfo = <s:property value='%{deltaTableData}'/>;
 deltaInfo = new dojo.data.ItemFileWriteStore({
     data: {
         items: rawdataDeltaInfo
     }
 });

This section of code to remove all the existng data take 2seconds, even though it only has 30 rows. Any ideas how to make this quicker?

 function requestJSONFeed(){
     // remove all existing data...
        var allData = deltaInfo._arrayOfAllItems;
     for (i=0;i<allData.length;i++) {
       if (allData[i] != null) {
        deltaInfo.deleteItem(allData[i]);
       }
     }
     deltaInfo.save();

     // make JSON XHR request...
   var xhrArgs = {
  url: "../secure/jsonServlet",
     handleAs: "json",
     preventCache: true,
     load: function(data) {
         // Add new items to the store...
       for (i=0;i<data.length;i++) {
        deltaInfo.newItem(data[i]);
      }
     },
     error: function(error) {
     }
 }

 //Call the asynchronous xhrGet
 var deferred = dojo.xhrGet(xhrArgs);

}

The section of code above to add 30 new items takes 4 seconds. Any ideas on how to make this faster?

Thanks!

Jeff Porter

FINAL CODE...

var xhrArgs = {
url: "../secure/jsonServlet",
 handleAs: "json",
 preventCache: true,
 load: function(datax) {
     deltaInfo = new dojo.data.ItemFileWriteStore({data: {items:datax}});
     var grid = dijit.byId("gridDeltas");
     grid.setStore(deltaInfo);
 },
 error: function(error) {
 }

Try skipping the code that walks through the existing store, deletes every item and then does deltaInfo.save() . Instead, create a brand new store based on your xhr call, and then use dojox.grid.DataGrid.setStore() .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM