问题
I have 2 comboboxes. The first selects a category, the second selects the sub category. Both categories are stored in one store with fields: id, parentId, label. Filtering the store isn't working since both comboboxes are bound to the same store.
How can I link the comboboxes? How can I filter the list of the second combobox?
回答1:
Instead of referring to the same store use Ext.create() to create a new instance of the same store for the second combo box. Use select or change listeners on comboboxes to trigger filtering from one to the other.
EDIT: Here is an example of such a beast :) http://extjs.wima.co.uk/example/1 This is not mine but sounds exactly what you are doing. Please note the way the stores are setup for each combo box. The first Combo CREATES a new store with the new operator - although this is not the best practice, it will work. The best practice is just to use Ext.create(..).
The second Combo refers to an existing store. In your case since you are reusing the same store definition you want to use Ext.create(...) on both Combos.
For more reference on best practices of class system read this guide: http://docs.sencha.com/ext-js/4-0/#!/guide/class_system
来源:https://stackoverflow.com/questions/8445340/linked-comboboxes-with-one-store-in-extjs-4-0