Reputation: 425
Is there a way to bind a store to a ExtJS ComboBox without creating a js model (ExtJS 4.1)?
To populate a users combobox I'll always need to set up the model first? I would like to skip the following code for each combobox:
Ext.define('User',{extend:'Ext.data.Model',idProperty:'Id',fields:['Id','Name']});
Upvotes: 4
Views: 12326
Reputation: 757
If you're using Architect you can specify an array in the store property for the ComboBox. There is no point to create extra stores & models if you just want a static 'Title' ComboBox.
xtype:'combo',
fieldLabel:'Title',
name:'division',
queryMode:'local',
store:['Mr','Mrs','Ms'],
displayField:'title',
autoSelect:true,
forceSelection:true
p.s. In order to change the store property to a local array in Architect you need to select the little icon on the left of the store text and change it to an array instead of a store.
Upvotes: 3
Reputation: 425
You're right, Neil!
I've found how to use it:
var myStore = Ext.create('Ext.data.Store',{
fields:['Id','Name'],
data:[
{Id:0,Name:'Yes'},
{Id:1,Name:'No'},
{Id:2,Name:'Maybe'}
]
});
var pnl = Ext.create('Ext.panel.Panel', {
xtype: 'panel',
title: 'My Panel',
items: [{
id:'cboField1'
xtype:'combobox',
fieldLabel:'My Field',
displayField:'Name',
valueField:'Id',
queryMode:'local',
store: myStore
}]
});
Upvotes: 3
Reputation: 48287
You do not need to set a model in a store in any situation in Extjs. Set the fields property of the store.
http://docs.sencha.com/ext-js/4-1/#!/api/Ext.data.AbstractStore-cfg-fields
Also, consider the data property of the store for local data.
http://docs.sencha.com/ext-js/4-1/#!/api/Ext.data.Store-property-data
Upvotes: 1
Reputation: 17860
I found it useful to create simple model with two fields id, name and then use this model on all static stores (which I use for comboboxes) where list of values is predefined.
Upvotes: 2