[英]Unable to add components(buttons) dyanamically in Enyo
我在Enyo中使用窗口视图,该视图基本上是从数据库中获取数据的,并且基于否。 提取项目后,将动态创建多个按钮。 单击任何按钮后,将再次调用数据库以获取其他项目集。 需要将提取的项目动态添加为<ul>项目作为按钮。 由代码完成-
testPOSView : function(inSender, inEvent) {
var data = inEvent.data;
console.log(data.tables);
enyo.forEach(data.tables, function(table) {
console.log(table);
this.$.sectiontablebar.createComponent({
kind : 'OB.OBPOSPointOfSale.UI.TablesButton',
button : {
kind : 'OB.UI.Section',
content: table.tableName,
id: table.tableId
}
});
}, this);
}
但是,当我单击该按钮时,我正在从DB获取结果,但结果未添加到sectiontablebar组件中。
该文件的完整代码可在@ https://gist.github.com/sangramanand/ad665db9cd438001254a获得
任何帮助,将不胜感激。 谢谢!!!
我不确定这是这样做的方法,但是当我动态创建子组件时,我将this.render()
添加到函数的末尾。 这将渲染组件,从而显示动态添加的内容。
如果我要重写您的代码,我会这样做:
testPOSView : function(inSender, inEvent) {
var data = inEvent.data;
enyo.forEach(data.tables, function(table) {
// create the sub-component in "this"
this.createComponent({
// and assign the container
container: this.$.sectiontablebar,
kind : 'OB.OBPOSPointOfSale.UI.TablesButton',
button : {
kind : 'OB.UI.Section',
content: table.tableName,
id: table.tableId
}
});
}, this);
this.render();
}
在异步调用以获取数据库结果后运行testPOSView时,很可能会丢失指向该指针的指针。
在您的anyTap函数中(请参见要点,读者),您可以尝试将要发送的函数绑定到OB.DS.Process:
this.bindSafely(function(data) {me.doTestPOSView();}))
顺便说一句,如果您正确地绑定了函数,则可能消除了我所有的一切。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.