我无法分辨为什么我的商店不会绑定从服务器返回的数据。提前谢谢。
以下是我实例化并调用“load”的方法:
var store = Ext.create('Iip.store.giip.other.States');
store.load({
params: {c: 'get_states'},
scope: this,
callback: function(records, operation, success) {
console.log(records); **<=== never prints**
}
});
这是商店:
Ext.define("Iip.store.giip.other.States", {
extend: "Ext.data.Store",
storeId:"states-store",
model: "Iip.model.giip.other.State",
autoLoad: false,
buffered: true
});
以下是模型:
Ext.define('Iip.model.giip.other.State', {
extend: 'Ext.data.Model',
idProperty: "stateId",
fields:[
{name: "stateId", type: "int"},
{name: "state", type: "string"}
],
proxy: {
type: "ajax",
actionMethods: {
read: "POST"
},
api: {
read: "indexes/common_index.php"
},
reader: {
type: "json",
root: "states"
},
listeners: {
exception: function(proxy, response, operation, opts) {
if(typeof(operation.error) == "string") {
Ext.Msg.alert("Error", "Connection to server interrupted");
}
}
}
}
});
以下是firebug中服务器返回的数据:
{"states":[{"stateId":"1","state":"AL"},{"stateId":"2","state":"AK"},
{"stateId":"3","state":"AS"},{"stateId":"4","state":"AZ"},{"stateId":"5","state":"AR"},
{"stateId":"6","state":"CA"},{"stateId":"7","state":"CO"},{"stateId":"8","state":"CT"},
{"stateId":"9","state":"DE"},{"stateId":"10","state":"DC"},
{"stateId":"11","state":"FM"},{"stateId":"12","state":"FL"},
{"stateId":"13","state":"GA"},{"stateId":"14","state":"GU"},
{"stateId":"15","state":"HI"},{"stateId":"16","state":"ID"},
{"stateId":"17","state":"IL"},{"stateId":"18","state":"IN"},
{"stateId":"19","state":"IA"},{"stateId":"20","state":"KS"},
{"stateId":"21","state":"KY"},{"stateId":"22","state":"LA"},
{"stateId":"23","state":"ME"},{"stateId":"24","state":"MH"},
{"stateId":"25","state":"MD"},{"stateId":"26","state":"MA"},
{"stateId":"27","state":"MI"},{"stateId":"28","state":"MN"},
{"stateId":"29","state":"MS"},{"stateId":"30","state":"MO"},
{"stateId":"31","state":"MT"},{"stateId":"32","state":"NE"},
{"stateId":"33","state":"NV"},{"stateId":"34","state":"NH"},
{"stateId":"35","state":"NJ"},{"stateId":"36","state":"NM"},
{"stateId":"37","state":"NY"},{"stateId":"38","state":"NC"},
{"stateId":"39","state":"ND"},{"stateId":"40","state":"MP"},
{"stateId":"41","state":"OH"},{"stateId":"42","state":"OK"},
{"stateId":"43","state":"OR"},{"stateId":"44","state":"PW"},
{"stateId":"45","state":"PA"},{"stateId":"46","state":"PR"},
{"stateId":"47","state":"RI"},{"stateId":"48","state":"SC"},
{"stateId":"49","state":"SD"},{"stateId":"50","state":"TN"},
{"stateId":"51","state":"TX"},{"stateId":"52","state":"UT"},
{"stateId":"53","state":"VT"},{"stateId":"54","state":"VA"},
{"stateId":"55","state":"VI"},{"stateId":"56","state":"WA"},
{"stateId":"57","state":"WV"},{"stateId":"58","state":"WI"},
{"stateId":"59","state":"WY"}]}
以下是数据应绑定到的组合:
{
xtype: 'combo',
fieldLabel: 'State',
store: store,
displayField: 'state',
valueField: 'stateId',
anchor:'97%',
itemId: 'fatherState',
editable: false,
allowBlank: false,
emptyText: 'Select a state',
tabIndex: 6,
queryMode: 'local'
}
答案 0 :(得分:0)
尝试更改后面的两个文件
存储
Ext.define("Iip.store.giip.other.States", {
extend: "Ext.data.Store",
config: {
storeId:"states-store",
model: "Iip.model.giip.other.State",
autoLoad: false,
buffered: true,
proxy: {
type: "ajax",
actionMethods: {
read: "POST"
},
api: {
read: "indexes/common_index.php"
},
reader: {
type: "json",
root: "states"
},
listeners: {
exception: function(proxy, response, operation, opts) {
if(typeof(operation.error) == "string") {
Ext.Msg.alert("Error", "Connection to server interrupted");
}
}
}
}
}
});
模型:
Ext.define('Iip.model.giip.other.State', {
extend: 'Ext.data.Model',
idProperty: "stateId",
fields:[
{name: "stateId", type: "int"},
{name: "state", type: "string"}
]
});