PDA

View Full Version : How to avoid copying the code when using similar buttons?



ershpush
28 Jul 2012, 10:25 AM
How to avoid copying the code in the next example:

items: [
{
xtype: 'button',
height: 23,
width: 23,
text: ' 0'
},
{
xtype: 'button',
height: 23,
width: 23,
text: 1
},
{
xtype: 'button',
height: 23,
width: 23,
text: 2
},
{
xtype: 'button',
height: 23,
width: 23,
text: 3
}
]

How to apply loop for(i=0; i<4; i++) {...} ? ~o)

el_chief
28 Jul 2012, 10:34 AM
Use the defaults config:

http://docs.sencha.com/ext-js/4-1/#!/api/Ext.container.AbstractContainer-cfg-defaults

vietits
28 Jul 2012, 4:08 PM
var items = [];
for(var i = 0; i < 4; i++){
items.push({
xtype: 'button',
height: 23,
width: 23,
text: i
});
}

// use in your config
...
items: items,
...

ershpush
29 Jul 2012, 1:45 AM
It was very useful for me!