【ExtJS实践】之六 :Combobox从后台获取JSON格局的数据
Admin
2012年7月3日名人名言:虚伪的友谊有如你的影子;当你在阳光下时,他会紧紧的跟着,但当你一旦横越过阴暗处时,它会立刻就离开你。——培根
1、直接看代码:
Ext.BLANK_IMAGE_URL = "extjs/resources/p_w_picpaths/default/s.gif"; var storeUnit = new Ext.data.JsonStore({ fields: [""units_code"", ""units_name""], url : "../Cost_JsonDb.ashx?tablename=cost_units", autoLoad:true, root : "units" }); // 单位(计量单位)的下拉列表 var comboUnit = new Ext.form.ComboBox({ store: storeUnit, displayField:""units_code"", typeAhead: true, mode: ""local"", forceSelection: true, triggerAction: ""all"", emptyText:""选择单位..."", OnFocus:true }); Ext.onReady(function(){ comboUnit.render("combo-div"); });
2、在实例化JsonStore时,须要指定的参数有:
fields : 绑定命据的字段
url : 获取后台数据的地址
autoload : 设置为true时,Ext会主动的调用url中指定的地址获取数据;设置为false,则须要履行JsonStore.load()来获取数据
root : 后台返回数据的根节点的名字。Ext中为combobox和grid绑定命据时,后台返回的数据必须有一个根节点,不然不克不及正确绑定。
3、后台需返回数据格局示例:
{ "units":[ {"units_code":"kg","units_name":"\u5343\u514B"}, {"units_code":"m","units_name":"\u7C73"}, {"units_code":"m2","units_name":"\u5E73\u65B9\u7C73"}, {"units_code":"m3","units_name":"\u7ACB\u65B9\u7C73"}, {"units_code":"t","units_name":"\u5428"} ] }
转载于:https://blog.51cto.com/laokaddk/1528474