Javascript 在Ext JS中的项目列表中重复元素
我有一段代码,其中包含一些布局中的项目。我想重复此项firstRowButtons最多次Javascript 在Ext JS中的项目列表中重复元素,javascript,extjs,Javascript,Extjs,我有一段代码,其中包含一些布局中的项目。我想重复此项firstRowButtons最多次 items: [ // for(i = 0; i < MaxNumber; i++) { xtype: 'firstRowButtons' }, { margin: '10 50 10 50', padding: '10 20 10 20', xtype: 'textfield',
items: [
// for(i = 0; i < MaxNumber; i++)
{
xtype: 'firstRowButtons'
},
{
margin: '10 50 10 50',
padding: '10 20 10 20',
xtype: 'textfield',
name: 'Name',
fieldLabel: 'Survey Name',
maxLength: 100,
allowBlank: false,
disabled: true
},
{
margin: '10 50 10 50',
padding: '10 20 10 20',
xtype: 'combo',
fieldLabel: 'Number of Questions',
name: 'NofQuestions',
queryMode: 'local',
store: ['1', '2', '3'],
displayField: 'noOfQuestions',
autoSelect: true,
forceSelection: true,
disabled: true,
},
]
}, {
padding: '10 10 10 10',
xtype: 'secondRowButtons'
},
我知道循环不能在数组中使用。注释只是为了显示逻辑并指出我要重复的数组元素
有什么帮助吗 您可以调用一个函数,该函数将返回一个items数组,并且您可以在构建数组时应用自定义逻辑。只需确保调用的函数范围正确即可
function buildItems(){
let items = [];
let maxNumber = 5;
for(let i = 0; i < maxNumber; i++) {
items.push({
xtype: 'firstRowButtons'
});
}
items.push({
margin: '10 50 10 50',
padding: '10 20 10 20',
xtype: 'textfield',
name: 'Name',
fieldLabel: 'Survey Name',
maxLength: 100,
allowBlank: false,
disabled: true
},
{
margin: '10 50 10 50',
padding: '10 20 10 20',
xtype: 'combo',
fieldLabel: 'Number of Questions',
name: 'NofQuestions',
queryMode: 'local',
store: ['1', '2', '3'],
displayField: 'noOfQuestions',
autoSelect: true,
forceSelection: true,
disabled: true
});
return items;
}
Ext.create('Ext.Panel', {
renderTo: Ext.getBody(),
items: buildItems()
});