2010-05-20 61 views
2

我想更改我的dojo.data.ItemFileWriteStore中的数据。ItemFileWriteStore:如何更改数据?

目前,我有...

var rawdataCacheItems = [{'cachereq':'14:52:03','name':'Test1','cacheID':'3','ver':'7'}]; 
var cacheInfo = new dojo.data.ItemFileWriteStore({ 
     data: { 
      identifier: 'cacheID', 
      label: 'cacheID', 
      items: rawdataCacheItems 
     } 
    }); 

我想打一个XHR请求,以获得新的数据JSON字符串来呈现。

我不能解决的是如何更改由ItemFileWriteStore持有的“项目”中的数据。

任何人都可以指向正确的方向吗?

感谢 杰夫·波特

回答

1

我会给Alex Cheng +1,因为他给我带来了解决方案。

这是我如何解决我的问题..

我JSONExtractor类...

private String setupCacheTabData() 
{ 
JSONArray jsonList = new JSONArray(); 

List<IDataDelivery> cacheDeliveryRecords = service.getCacheDeliveryRecords(); 

for (IDataDelivery cache : cacheDeliveryRecords) 
{ 
    JSONObject jsonO = new JSONObject(); 
    try 
    { 
    jsonO.put("cacheID", cache.getCacheID()); 
    jsonO.put("cacheversion", cache.getVersion()); 
    jsonList.put(jsonO); 
    } 
    catch (Exception e) 
    { 
    log.error("Error decoding CACHE database row for JSON (WILL SKIP): CACH_ID=" + cache.getCacheID(), e); 
    } 
} 

return jsonList.toString().replace("\"", "'"); 

}

我的javascrip代码...

var cacheInfo; 

var rawdataCacheInfo = <s:property value='%{cacheString}'/>; 
cacheInfo = new dojo.data.ItemFileWriteStore({ 
     data: { 
      identifier: 'cacheId', 
      label: 'cacheId', 
      items: rawdataCacheInfo 
     } 
    }); 

function do() { 
    var xhrArgs = { 

     url: "../secure/jsonServlet?class=JSONExtractor&startDate="+startDateValue+"&startTime="+startTimeValue, 
     handleAs: "json", 
     preventCache: true, 
     load: function(data) { 
      // remove items... 
      var allData = cacheInfo._arrayOfAllItems; 
      for (i=0;i<allData.length;i++) { 
       if (allData[i] != null) { 
        cacheInfo.deleteItem(allData[i]); 
       } 
      } 
      // save removal of items. 
      ddInfo.save(); 
      // add new items 
      for (i=0;i<data.length;i++) { 
       cacheInfo.newItem(data[i]); 
      } 

     }, 
     error: function(error) { 
     } 
    } 
} 
4

您可以使用dojo.data.api.Write API提供的功能来修改在商店的项目。

例如,您可以使用newItem在商店中创建新商品,使用deleteItem删除商店中的商品并使用setValue更新现有商品的属性。

0

@Jeff Porter

在您的代码中,您会说“ddInfo.save();

我没有看到这个名字实例化的任何变量。

您是不是要找 'cacheInfo.save()'?