Ext 3.4 - 如何使用本地数组即时填充组合框
Ext 3.4 - How the populate a combo box using a local array on the fly
我在 Ext 3.4 的 window 中有一个单选按钮。根据单击哪个单选按钮,我必须在组合框中相应地填充数据。
例如:单选按钮:1. Window 2. Linux。
如果用户选中 Window,则所有 windows 图像都将填充到组合框中。
现在为了获取所有 window 图像,我没有调用服务器来获取这些图像,而是将其作为存储在本地数组中的客户端。
以下是代码片段:
var ImagesArray = new Array();
ImagesArray=[];// On load the array contains no data
{
xtype: 'radiogroup',
fieldLabel: 'Image type',
cls: 'x-check-group-alt',
itemid: 'ImageType',
items: [
{boxLabel: 'WindowsImages', name: 'rb-auto', inputValue: 'Windows', id: 'Windows',checked:true,
listeners: {
'check' : function(radio, checked) {
data =['Windows 2008 Server','Windows 2012 server'];
ImagesArray.loadData(data,false);
ImagesArray.store.reload();
}
},
// My combo box
{
xtype : 'combo', // 6
fieldLabel : 'Template/Image name',
id: 'VMTemplate',
name: 'VMTemplate',
labelWidth: 250,
triggerAction: 'all',
forceSelection: true,
editable:false,
store : ImagesArray,
},
但这不起作用。我收到错误 store.reload() 未定义。
我如何让它发挥作用?
由于可以进行多选,我认为checkboxgroup比radiogroup更适合你的情况。示例代码。
Ext.create('Ext.form.Panel', {
width: 300,
height: 500,
bodyPadding: 10,
renderTo: Ext.getBody(),
items:[{
xtype: 'checkboxgroup',
fieldLabel: 'Two Columns',
columns: 2,
vertical: true,
listeners:{
change: function(){
var data = Ext.Array.flatten(Ext.Object.getValues(this.getValue()));
data = data.map(function(n){ return { name: n } });
Ext.getCmp("VMTemplate").getStore().loadData(data);
}
} ,
items: [
{ boxLabel: 'Item 1', name: 'rb-auto', inputValue: 'Item 1'},
{ boxLabel: 'Item 2', name: 'rb-auto', inputValue: 'Item 2'},
{ boxLabel: 'Item 3', name: 'rb-auto', inputValue: 'Item 3' },
{ boxLabel: 'Item 4', name: 'rb-auto', inputValue: 'Item 4' },
{ boxLabel: 'Item 5', name: 'rb-auto', inputValue: 'Item 5' },
{ boxLabel: 'Item 6', name: 'rb-auto', inputValue: 'Item 6' }
]
},{
xtype: 'combo',
store:{
fields: ['name'],
data: []
},
displayField: 'name',
valueField: 'name',
emptyText: 'Template',
id: 'VMTemplate',
queryMode: 'local'
}]
});
我在 Ext 3.4 的 window 中有一个单选按钮。根据单击哪个单选按钮,我必须在组合框中相应地填充数据。
例如:单选按钮:1. Window 2. Linux。 如果用户选中 Window,则所有 windows 图像都将填充到组合框中。 现在为了获取所有 window 图像,我没有调用服务器来获取这些图像,而是将其作为存储在本地数组中的客户端。 以下是代码片段:
var ImagesArray = new Array();
ImagesArray=[];// On load the array contains no data
{
xtype: 'radiogroup',
fieldLabel: 'Image type',
cls: 'x-check-group-alt',
itemid: 'ImageType',
items: [
{boxLabel: 'WindowsImages', name: 'rb-auto', inputValue: 'Windows', id: 'Windows',checked:true,
listeners: {
'check' : function(radio, checked) {
data =['Windows 2008 Server','Windows 2012 server'];
ImagesArray.loadData(data,false);
ImagesArray.store.reload();
}
},
// My combo box
{
xtype : 'combo', // 6
fieldLabel : 'Template/Image name',
id: 'VMTemplate',
name: 'VMTemplate',
labelWidth: 250,
triggerAction: 'all',
forceSelection: true,
editable:false,
store : ImagesArray,
},
但这不起作用。我收到错误 store.reload() 未定义。 我如何让它发挥作用?
由于可以进行多选,我认为checkboxgroup比radiogroup更适合你的情况。示例代码。
Ext.create('Ext.form.Panel', {
width: 300,
height: 500,
bodyPadding: 10,
renderTo: Ext.getBody(),
items:[{
xtype: 'checkboxgroup',
fieldLabel: 'Two Columns',
columns: 2,
vertical: true,
listeners:{
change: function(){
var data = Ext.Array.flatten(Ext.Object.getValues(this.getValue()));
data = data.map(function(n){ return { name: n } });
Ext.getCmp("VMTemplate").getStore().loadData(data);
}
} ,
items: [
{ boxLabel: 'Item 1', name: 'rb-auto', inputValue: 'Item 1'},
{ boxLabel: 'Item 2', name: 'rb-auto', inputValue: 'Item 2'},
{ boxLabel: 'Item 3', name: 'rb-auto', inputValue: 'Item 3' },
{ boxLabel: 'Item 4', name: 'rb-auto', inputValue: 'Item 4' },
{ boxLabel: 'Item 5', name: 'rb-auto', inputValue: 'Item 5' },
{ boxLabel: 'Item 6', name: 'rb-auto', inputValue: 'Item 6' }
]
},{
xtype: 'combo',
store:{
fields: ['name'],
data: []
},
displayField: 'name',
valueField: 'name',
emptyText: 'Template',
id: 'VMTemplate',
queryMode: 'local'
}]
});