版本3.0
后台代码:
public JsonResult City() { return Json("{\"data\":[{\"id\":1,\"name\":\"北京\"}]}", JsonRequestBehavior.AllowGet); }
js:
Ext.onReady(function () { //创建市数据源 var combocitystore = new Ext.data.Store({ //设定读取的地址 proxy: new Ext.data.HttpProxy({ url: 'combobox/City' }), //设定读取的格式 reader: new Ext.data.JsonReader({ root: 'data' }, [ { name: "id" }, { name: "name"}]) }); //创建市Combobox var comboboxcity = new Ext.form.ComboBox({ id: 'comboboxcity', fieldLabel: '市', width: 120, store: combocitystore, displayField: 'name', valueField: 'id', triggerAction: 'all', emptyText: '请选择...', allowBlank: false, blankText: '请选择市', editable: false, mode: 'local', //该属性和以下方法为了兼容ie8 listeners: { 'render': function () { combocitystore.load(); alert(combocitystore.getCount()); } } }); //----------------------下拉列表结束----------------------// //表单 var form = new Ext.form.FormPanel({ frame: true, title: '表单标题', style: 'margin:10px', items: [comboboxcity, comboareacity] }); //窗体 var win = new Ext.Window({ title: '窗口', width: 476, height: 374, resizable: true, modal: true, closable: true, maximizable: true, minimizable: true, buttonAlign: 'center', items: form }); win.show(); ---自己写的ajax是正常的 $.ajax({ type: "post", url: 'combobox/City', data: null, dataType: "json", success: function (data) { var d = $.parseJSON(data); } }); });
原因combocitystore 为null 是什么原因呢?
脚本无错误
extjs