1

我正在尝试来自此链接的示例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 

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

4

2 回答 2

0

非常遗憾。但我刚刚找到了一种方法来做我正在尝试的事情:

  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();
    }

它工作得非常好......;)再一次,抱歉问和回答同样的问题......

于 2013-01-23T04:34:49.567 回答
0

使用 RoundRectDataList.refresh 函数有一种更简单的方法可以将 ItemFileReadStore 重新加载到RoundRectDataList中。

 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) {
var self = this;

populateVistoriasList = function() {
  var idx = 'vistoriasList',
      vistoriasList = dijit.byId( idx );

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

  if ( vistoriasList && vistoriasList instanceof roundRectDataList ) {
    vistoriasList.store = self.sampleStore;
    vistoriasList.refresh(); 
  } else {
    self.dataList = new roundRectDataList({store:self.sampleStore}, idx );
    self.dataList.startup();
  }
}
于 2013-02-25T15:38:31.057 回答