如何在Enyo中运行时创建按钮?

时间:2012-01-01 19:58:34

标签: enyo

我需要一个应用程序来显示在运行时创建的按钮。原因是我将从服务中获取信息以查看我需要多少按钮。

目前程序已运行,但未显示任何按钮。

我正在尝试使用工具栏并在create function中设置control属性。该程序运行正常,但我的工具栏没有按钮?有没有办法做到这一点?

代码:

// Trying to create buttons at run time
name: "MyApps.MainApp",
kind: enyo.VFlexBox,
components: [
        {kind: "PageHeader", content: "Template"},
        {kind: "Toolbar", name: "tabsted"},
        {name: "feedUrl", kind: "Input", flex: 1},
        {kind: "HtmlContent", name: "comments", content: "hello world <br> and another lin"},
        {name:"curValue", content:("Sample Text \r\n and more")},
        {kind: "Button", caption: "Action", onclick: "btnClick"},
],

// this gets called first ha
create: function()
{
    this.inherited(arguments);

    this.$.tabsted.components= [
            {caption: "a"},
            {caption: "b"},
            {caption: "c"}
    ];

    this.LoadCommments();
    },

    LoadCommments: function()
    {
        this.$.comments.content="fred";   
    },

    // called when button is clicked
    btnClick: function() 
    {
        this.$.curValue.setContent("Put some text here");  // handle the button click
    }
};

1 个答案:

答案 0 :(得分:2)

您需要查看Enyo.Component的API文档。具体来说,是关于动态创建组件的部分。请尝试对您的代码进行以下更改:

    this.$.tabsted.createComponents([
        {caption: "a"},
        {caption: "b"},
        {caption: "c"}
    ], {owner: this});

此外,在LoadComments函数中,您需要调用'setContents',而不是尝试直接更新内容的值。