1

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

当前程序正在运行,但没有显示任何按钮。

我正在尝试使用工具栏并在创建函数中设置控件属性。程序运行正常,但我的工具栏没有按钮?有没有办法做到这一点?

代码:

// 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
    }
};
4

1 回答 1

2

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

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

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

于 2012-01-02T05:41:51.583 回答