代码之家  ›  专栏  ›  技术社区  ›  jeff porter ichak khoury

itemFileWriteStore:如何更改数据?

  •  2
  • jeff porter ichak khoury  · 技术社区  · 15 年前

    我想更改dojo.data.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保存的“items”中的数据。

    有人能指出我的正确方向吗?

    谢谢 杰夫波特

    3 回复  |  直到 13 年前
        1
  •  4
  •   Fu Cheng    15 年前

    您可以使用 dojo.data.api.Write 用于修改存储区中的项的API。

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

        2
  •  1
  •   jeff porter ichak khoury    15 年前

    我会把+1给Alex Cheng,因为他告诉我解决方案。

    这就是我解决问题的方法。

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

    }

    我的javastrip代码…

    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) {
            }
        }
    }
    
        3
  •  0
  •   7dr3am7    13 年前

    @ Jeff Porter

    在你的代码里你说 DeFix.SaveE();

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

    你是说 cacheinfo.save()保存 “?