inane
inane

Reputation: 648

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..

Upvotes: 0

Views: 468

Answers (2)

CD..
CD..

Reputation: 74166

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

Upvotes: 1

gautham city
gautham city

Reputation: 50

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();

Upvotes: 0

Related Questions