简体   繁体   中英

Dynamic segmented button in sencha touch

I am working in a Sencha Touch application and I need to create a dynamic segmented button with different number of items from the controller instead of add to the view each time this component.

Correct way for this It should be create a singleton class and call to this when you need create the component... right?

Thank you..

You can use setItems :

Sets the value of items.

For example:

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

Working example: https://fiddle.sencha.com/#fiddle/1035

Give id to button in view:

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

then in controller:

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

and depending on your requirement you can use:

this.getBtnStudents().show();

or this.getBtnStudents().hide();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM