【问题标题】:Dynamic segmented button in sencha touchsencha touch 中的动态分段按钮
【发布时间】:2015-10-26 13:57:34
【问题描述】:

我正在使用 Sencha Touch 应用程序,我需要从控制器创建一个具有不同数量项目的动态分段按钮,而不是每次都添加到视图中。

正确的方法应该是创建一个单例类并在需要创建组件时调用它...对吗?

谢谢你..

【问题讨论】:

    标签: javascript extjs sencha-touch


    【解决方案1】:

    你可以使用setItems:

    设置项目的值。

    例如:

    segmentedButton.setItems([{text: 'Option 4'}, {text: 'Option 5'}])
    

    工作示例:https://fiddle.sencha.com/#fiddle/1035

    【讨论】:

    • 谢谢!!!它对我来说工作正常,我正在工作,但是..现在我很高兴!! :-)
    【解决方案2】:

    为视图中的按钮提供 id:

    {
                        xtype: 'segmentedbutton',
                        allowToggle: false,
                        layout: {
                            type: 'hbox',
                            align: 'end'
                        },
                        items: [
                            {
                                xtype: 'button',
                                id: 'btnStudents',
                                text: 'student'
                            },
                            {
                                xtype: 'button',
                                id: 'btnTeacher',
                                text: 'teacehr'
                            }
                        ]
                    }
    

    然后在控制器中:

    refs: {
            btnStudents: 'button#btnStudents',
            btnTeacher: 'button#btnTeacher',
        },
    

    根据您的要求,您可以使用:

    this.getBtnStudents().show();
    

    this.getBtnStudents().hide();

    【讨论】:

    • 感谢您的回复,但我想动态添加而不是显示或隐藏项目..
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-05-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-11
    相关资源
    最近更新 更多