我正在尝试从此链接http://livedocs.dojotoolkit.org/dojox/mobile/RoundRectDataList中输入一个示例:

require([
    "dojo/ready",
    "dojo/data/ItemReadStore",
    "dojox/mobile/RoundRectDataList",
    "dojox/mobile",
    "dojox/mobile/parser"
], function(ready, ItemFileReadStore, RoundRectDataList){
    ready(function(){
        var storeData = {
            "items": [
                { "label": "Wi-Fi", "icon": "images/i-icon-3.png", "rightText": "Off",  "moveTo": "bar" },
                { "label": "VPN", "icon": "images/i-icon-4.png", "rightText": "VPN",  "moveTo": "bar" }
            ]
        };
        var sampleStore = new ItemFileReadStore({data:storeData});
        var dataList = new RoundRectDataList({store:sampleStore}, "dataList");
        dataList.startup();
    });
});


和html部分:

<ul id="dataList"></ul>


问题是我不能将其放在按钮上并重复相同的代码。因为得到这个错误:

Uncaught Error: Tried to register widget with id==dataList but that id is already registered


如果我销毁或清空该节点,该节点不再显示...。我该怎么办?销毁并在DOM上创建相同的<ul>

最佳答案

非常遗憾。但是我只是找到了一种方法来做我想做的

  require([
    "dojo/on",
    "dojo/dom",
    "dojo/dom-construct",
    "dojox/mobile/parser",    // This mobile app uses declarative programming with fast mobile parser
    "dojox/mobile",           // This is a mobile app.
    "dijit/dijit",
    "dijit/registry",
    "dojo/data/ItemFileReadStore",
    "dojox/mobile/RoundRectDataList",
    "dojo/_base/array",
    "dojo/domReady!"
  ], function(on, dom, domConstruct, parse, mobile, dijit, registry, itemFileReadStore, roundRectDataList) {
    self = this;

    populateVistoriasList = function() {
      var idx = 'vistoriasList'
      var vistoriasList = dijit.byId( idx );
      if ( vistoriasList && vistoriasList instanceof roundRectDataList )
        vistoriasList.destroyRecursive(false);

      domConstruct.destroy( idx );
      domConstruct.create('ul', {id: idx }, 'vistoriasListContainer');

      self.storeData = {
          "items": [
              { "label": "Wi-Fi", "icon": "images/i-icon-3.png", "rightText": "Off", "moveTo": "bar" },
              { "label": "VPN", "icon": "images/i-icon-4.png", "rightText": "VPN", "moveTo": "bar" }
          ]
      };
      self.sampleStore = new itemFileReadStore({data:storeData});
      self.dataList = new roundRectDataList({store:sampleStore}, idx );
      self.dataList.startup();
    }


它工作得很好...;)
再说一次,很抱歉提出和回答相同的问题...

关于javascript - 如何更新RoundRectDataList(在Dojo +1.7中)?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/14467291/

10-12 03:42