PDA

View Full Version : How to avoid copying the code in "items: [ ]"?



ershpush
28 Jul 2012, 8:02 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)

qqtgg
31 Jul 2012, 1:16 AM
is this code for preventing copy? :D

sword-it
31 Jul 2012, 2:09 AM
hi!

you may try this code:-





var itemArr = []
, totalCount=4; // no of times loop executes

for (var i = 0; i < totalCount; i++) {
itemArr.push(
{
xtype: 'button',
height:23,
width:23,
text: i+1
}
);
}
return itemArr;