最近新接触的extjs,需要写下拉框,实现城市与所在街道的联动。用了两种方法。一种是应用filterBy方法 ,另一种是应用store的proxy直接查找。数据量大的时候使用第二种方法。
先介绍两种概念,都是API文档中的定义,个人认为,阅读API文档是接触新语言时最有效的方法。
1.proxy:Proxies are used by Stores to handle the loading and saving of Model data. Usually developers will not need to create or interact with proxies directly.
2.filterBy( fn, [scope] ):Filters by a function. The specified function will be called for each Record in this Store. If the function returns true the Record is included, otherwise it is filtered out
说明一下,我在定义下拉框组件的时候用的是itemId,所以获取组件不能使用Ext.getCmp方法。
一、方法一
除了数据选择部分,其余内容不变
二、方法二
两个下拉框的代码:{
xtype: ‘combobox’,
fieldLab