你可以將服務器結構更改爲像這樣的標準extjs json存儲格式嗎?如果是這樣,你的店的設置將非常簡單:
{
"content":[
{
"shipping_type":"ups_ground",
"amount":"7.06",
"currency_code":"USD",
"data":[],
"tnt":"Monday, 7\/15 at 11:00pm"
},
{
"shipping_type":"ups_next_day_air_saver",
"amount":"26.44",
"currency_code":"USD",
"data":[],
"tnt":"Monday, 7\/15 at 3:00pm"
},
{
"shipping_type":"ups_next_day_early_a.m.",
"amount":"63.84",
"currency_code":"USD",
"data":[],
"tnt":"Monday, 7\/15 at 8:30am"
},
{
"shipping_type":"ups_next_day_air",
"amount":"30.99",
"currency_code":"USD",
"data":[],"tnt":
"Monday, 7\/15 at 10:30am"
}
]
}
而且你可以聲明模型和存儲這樣的:
Ext.define("ShippingModel", {
extend: "Ext.data.Model",
fields: [
{name:"shipping_type", type:"string"},
{name:"amount", type:"float"},
{name:"currency_code", type:"string"},
{name:"data", type:"string"},
{name:"tnt", type:"string"}//this may need to be a date, lookup date format for this yourself
]
});
Ext.create('Ext.data.Store', {
model: 'ShippingModel',
controller: 'news',
proxy: {
type: 'ajax',
url: 'your url',
reader: {
type: 'json',
root: 'content'
},
extraParams:{
action:'getShippingRates'//you may not need the extraParams, just putting here for example
}
},
autoLoad: true
});
如果你不能做這樣的認定標準,可以擴展閱讀器類來讀取您的自定義數據結構。它看起來像這樣:
Ext.define("MyWeirdlyStucturedDataReader", {
extend: "Ext.data.reader.Json",
extractData: function(root){
var newStructure = [];
for(var shippingType in root)
{
var newRecord = root[shippingType];
newRecord.shipping_type = shippingType;
newStructure.push(newRecord);
}
return this.callParent(newStructure);
}
});
然後,您將代理中的reader類型屬性設置爲'MyWeirdlyStucturedDataReader'。
*此代碼全部未經測試,即使不起作用,它應該讓您知道該怎麼做。
謝謝你...改變了json .. – GiGi