版本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 是什么原因呢?
腳本無錯誤
添加回答
舉報
0/150
提交
取消