This is because of project requirements. I will send it for your reference.
The idea at the beginning was to load the data through the defined array through the loadData method of the combobox store. Later, we found that it is better to directly define the array format as the store format, it is easier to directly attach the data to the store and facilitate loading of city data.
Let's take a look at the definitions of two comboboxes:
|
Var provinceComBo = new Ext. form. ComboBox ({
HiddenName: 'vince ',
Name: 'province _ name ',
ValueField: "text ",
DisplayField: "text ",
Mode: 'local ',
FieldLabel: 'province ',
BlankText: 'select a province ',
EmptyText: 'select a province ',
Editable: false,
Anchor: '20140901 ',
ForceSelection: true,
TriggerAction: 'all ',
Store: new Ext. data. SimpleStore ({fields: ["text", "city"], data: citys, sortInfo: {field: 'text '}}),
Listeners :{
Select: function (combo, record, index ){
CityCombo. clearValue ();
CityCombo. store. loadData (record. data. city );
}
}
})
Var cityCombo = new Ext. form. ComboBox ({
HiddenName: 'city ',
Name: 'city _ name ',
ValueField: "text ",
DisplayField: "text ",
Mode: 'local ',
FieldLabel: 'city ',
BlankText: 'select a city ',
EmptyText: 'select a city ',
Editable: false,
Anchor: '20140901 ',
ForceSelection: true,
TriggerAction: 'all ',
Store: new Ext. data. SimpleStore ({fields: ["text"], data: [], sortInfo: {field: 'text '}})
}); |
I will not elaborate on other definitions of comboBox. If you are interested, refer to my article Ext2.0 form use instance. We will focus on its definition of sotre. The provincial store is defined as follows:
|
Store: new Ext. data. SimpleStore ({fields: ["text", "city"], data: citys, sortInfo: {field: 'text '}}),
Listeners :{
Select: function (combo, record, index ){
CityCombo. clearValue ();
CityCombo. store. loadData (record. data. city );
}
} |
Store defines two fields. The first field is the display and Value Field of the province. The second field is special and stores the city array of the province. The advantage is that when selecting an event, you can directly transfer the data in the city field to the city store to select the city in the province, avoid processing data cyclically. However, before loading data in a city, you must clear the selected input value (cityCombo. clearValue ();).
The store definition of the city combobox is nothing special, that is, the city name can be displayed.
In the two comboboxes, I also set a sort (sortInfo: {field: 'text'}), which makes it easier. However, to sort by Chinese, you must reload the applySort attribute of store. For details, refer to the address below:
Http://jstang.5d6d.com/thread-362-1-4.html
For specific data definitions, see city. js in the routine.
What if I need an id? Redefine the store field and modify the data definition of the city. If the data is in the background, you can dynamically modify the city url by selecting a province.
We hope that through this example, you can easily make other examples of combobox interaction.
Click here to download the routine.