Cordova 如何将dojox.mobile.ListItem动态添加到RoundRectList?

Cordova 如何将dojox.mobile.ListItem动态添加到RoundRectList?,cordova,dojo,ibm-mobilefirst,Cordova,Dojo,Ibm Mobilefirst,我正在尝试将dojox.mobile.ListItems动态添加到dojox.mobile.RoundRectList中,并且正在努力解决一些应该相对简单的问题 这是我的dojo小部件: <ul data-dojo-type="dojox.mobile.RoundRectList" id="theTable" > <li data-dojo-type="dojox.mobile.ListItem" data-dojo-props='ico

我正在尝试将
dojox.mobile.ListItem
s动态添加到
dojox.mobile.RoundRectList
中,并且正在努力解决一些应该相对简单的问题

这是我的dojo小部件:

<ul data-dojo-type="dojox.mobile.RoundRectList" id="theTable" >
        <li data-dojo-type="dojox.mobile.ListItem"
            data-dojo-props='icon:"images/i-icon-1.png",
                            moveTo:"#article",
                            variableHeight:true' 
            id="theItem">
            text here
        </li>
    </ul>
这似乎不起作用,特别是在Chrome的Javascript控制台中显示以下错误:

未捕获的TypeError:无法调用未定义的方法“addChild”

有人能告诉我我做错了什么吗?本质上,我有一个JSON对象,我正试图迭代它并将元素放入一个列表中


谢谢

我不能100%准确地确定这是否是导致问题的原因,但您可能应该使用Dojo API(特别是,
Dojo.place
)将此列表项放置在列表中,而不是使用JavaScript/DOM API。e、 g

dojo.place(childWidget.domNode, theTable) 

我不能100%准确地确定这是否是导致问题的原因,但您可能应该使用Dojo API(特别是,
Dojo.place
)将此列表项放置在列表中,而不是使用JavaScript/DOM API。e、 g

dojo.place(childWidget.domNode, theTable) 

错误消息似乎表明您的theTable变量没有指向具有addChild()函数的对象-这意味着dojo.byId()已失败

我建议先检查一下表中的内容

作为比较,我有一些工作代码在做您试图做的事情,但我使用的是一种稍微不同的习惯用法:

我正在创建一个自己的小部件,所以我使用attachPoint-dapTaskList来获取一个句柄,以便将列表放置在哪里,并从头开始创建列表

var ul  = new RoundRectList({}, domConstruct.create("ul",{}, this.dapTaskList) );
ul.startup();
然后添加代码如下的项目:

        li = new ListItem({
          "label"          : "xx",
          "rightText"      : 997, 
          "class"          : "subTotalListItem"
        }, domConstruct.create("li",{}, ul.domNode) );
        li.startup();

错误消息似乎是说您的theTable变量没有指向带有addChild()函数的对象,这意味着dojo.byId()已失败

我建议先检查一下表中的内容

作为比较,我有一些工作代码在做您试图做的事情,但我使用的是一种稍微不同的习惯用法:

我正在创建一个自己的小部件,所以我使用attachPoint-dapTaskList来获取一个句柄,以便将列表放置在哪里,并从头开始创建列表

var ul  = new RoundRectList({}, domConstruct.create("ul",{}, this.dapTaskList) );
ul.startup();
然后添加代码如下的项目:

        li = new ListItem({
          "label"          : "xx",
          "rightText"      : 997, 
          "class"          : "subTotalListItem"
        }, domConstruct.create("li",{}, ul.domNode) );
        li.startup();

要访问dojo小部件,您需要使用dijit.byId而不是dojo.byId。byId用于访问未widgetized的DOM节点。我在下面提供了一个示例,但我建议查看dojox.mobile.RoundRectDataList,而不是普通的dojox.mobile.RoundRectList。数据列表版本由dojo.data.store支持,允许更轻松地进行动态更新-


指数
需要([“dojox/mobile/parser”,
“dijit/注册表”,
“dojox/mobile/deviceTheme”,
“dojox/mobile”,
“dojo/domReady!”],函数(解析器、注册表){
parser.parse();
var list=registry.byId(“list”);
var childWidget=new dojox.mobile.ListItem({id:“item1”,
图标:“images/icon.png”,
rightText:“关闭”,
移动到:“酒吧”,
标签:“u1space”});
list.addChild(childWidget);
});
设置
  • 转到文章视图
文章 这是文章的观点
要访问dojo小部件,您需要使用dijit.byId而不是dojo.byId。byId用于访问未widgetized的DOM节点。我在下面提供了一个示例,但我建议查看dojox.mobile.RoundRectDataList,而不是普通的dojox.mobile.RoundRectList。数据列表版本由dojo.data.store支持,允许更轻松地进行动态更新-


指数
需要([“dojox/mobile/parser”,
“dijit/注册表”,
“dojox/mobile/deviceTheme”,
“dojox/mobile”,
“dojo/domReady!”],函数(解析器、注册表){
parser.parse();
var list=registry.byId(“list”);
var childWidget=new dojox.mobile.ListItem({id:“item1”,
图标:“images/icon.png”,
rightText:“关闭”,
移动到:“酒吧”,
标签:“u1space”});
list.addChild(childWidget);
});
设置
  • 转到文章视图
文章 这是文章的观点