开发者

ItemFileWriteStore: how to change the data?

I'd like to change the data in my dojo.data.ItemFileWriteStore.

Currently I have...

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

I'd like to make a XHR request to get a new JSON string of the data to render.

What I can't work out is how to change the data in the "items" held by ItemFileWriteStore.

Can anyone point me in the correct direction?

Thanks Jeff Porter


You can use functions provided by dojo.data.api.Write API to modify the items in a store.

For example, you can use newItem to create a new item in the store, use deleteItem to remove an item in the store and use setValue to update attributes of an existing item.


I'll give +1 to Alex Cheng since he info lead me to the solution.

This is how I solved my problem..

My JSONExtractor class...

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("\"", "'");

}

My Javascrip code...

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) {
        }
    }
}


@Jeff Porter

In your code you say " ddInfo.save(); "

I don't see any variables instantiated with that name.

Did you mean 'cacheInfo.save()' ?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜