Extjs 在下面的代码中动态添加项
下面是我用来向容器添加自定义单元格组件的代码。在这里,我手动添加组件,但在我的实际应用程序中,它只会在客户端浏览器上知道需要添加多少组件。因此,是否有可能以某种方式动态添加这些组件,而不是像我现在这样手动添加Extjs 在下面的代码中动态添加项,extjs,extjs4,Extjs,Extjs4,下面是我用来向容器添加自定义单元格组件的代码。在这里,我手动添加组件,但在我的实际应用程序中,它只会在客户端浏览器上知道需要添加多少组件。因此,是否有可能以某种方式动态添加这些组件,而不是像我现在这样手动添加 Ext.define('TableRow',{ extend: 'Ext.container.Container', alias: 'widget.tablerow', width: '100%', layout: {
Ext.define('TableRow',{
extend: 'Ext.container.Container',
alias: 'widget.tablerow',
width: '100%',
layout: {
type: 'table',
columns: totalColumnsToDraw
},
items:[
{xtype: 'cell'},{xtype: 'cell'},{xtype: 'cell'},{xtype: 'cell'},{xtype: 'cell'},{xtype: 'cell'},{xtype: 'cell'},
{xtype: 'cell'},{xtype: 'cell'},{xtype: 'cell'},{xtype: 'cell'},{xtype: 'cell'},{xtype: 'cell'},{xtype: 'cell'},
{xtype: 'cell'},{xtype: 'cell'},{xtype: 'cell'},{xtype: 'cell'},{xtype: 'cell'},{xtype: 'cell'},{xtype: 'cell'},
{xtype: 'cell'},{xtype: 'cell'},{xtype: 'cell'},{xtype: 'cell'}
]
});
您可以重写类中的函数,并在其中动态生成items数组:
Ext.define('TableRow',{
extend: 'Ext.container.Container',
alias: 'widget.tablerow',
width: '100%',
layout: {
type: 'table',
columns: totalColumnsToDraw
},
numberOfCells: 10, // default number of cells, can be set on instantiation
initComponent: function() {
this.items = [];
for (var i = 0; i < this.numberOfCells; i++) {
this.items.push({xtype: 'cell'});
}
this.callParent();
}
});
// create component with 50 cells
Ext.create('TableRow', {
numberOfCells: 50
});
Ext.define('TableRow'{
扩展:“Ext.container.container”,
别名:“widget.tablerow”,
宽度:“100%”,
布局:{
键入:“表”,
列:totalColumnsToDraw
},
numberOfCells:10,//可以在实例化时设置默认的单元格数
initComponent:function(){
此参数为.items=[];
对于(var i=0;i