我在调试这个并获得解决方案时遇到了一些麻烦。
我的数据正确地返回给我,但是当我在'loadexception'函数上设置断点时,它会抛弃TypeError。这是错误:
description - “'prototype'为null或不是对象” 消息 - “'prototype'为null或不是对象” 名称 - “TypeError” 号码 - -2146823281
因此即使我的数据正确回归,我的callbox消息框也总是被错误引发。
V2020.dsPricing = new Ext.data.JsonStore({
proxy: new Ext.data.HttpProxy({
method: 'POST',
url: url,
headers: {"Content-Type": "application/json; charset=utf-8"},
jsonData: Ext.util.JSON.encode({ serviceId: objPricingReturn.serviceId })
}),
reader: PricingJsonReader()
});
V2020.dsPricing.on('loadexception', function(obj, options, response, err) {
Ext.MessageBox.show({
title: 'Error',
msg: url + ' POST method fail...ErrorCode:' + response.status,
buttons: Ext.MessageBox.OK,
icon: Ext.MessageBox.ERROR
});
});
V2020.dsPricing.load({
callback: function(records, o, s) {
if (!s) Ext.MessageBox.show({
title: 'Error',
msg: ' Failed to load pricing data',
buttons: Ext.MessageBox.OK,
icon: Ext.MessageBox.ERROR
});
}
});
这是JsonReader代码
function PricingJsonReader() {
var pricingReaderObject = new Ext.data.JsonReader({
root: 'GetServicePriceByIdResult.ServicePricing',
fields: [{
name: 'priceId',
type: 'int'
},
{
name: 'serviceId',
type: 'int'
},
{
name: 'price',
type: 'float'
},
{
name: 'startDate',
type: 'date',
dateFormat: 'n/j/Y'
},
{
name: 'endDate',
type: 'date',
dateFormat: 'n/j/Y'
},
{
name: 'updatedBy',
type: 'string'
},
{
name: 'updateDate',
type: 'date',
dateFormat: 'n/j/Y'
}]
})
return pricingReaderObject;
}
回应(我认为这就是你所要求的)
{"GetServicePriceByIdResult":{"ServicePricing":[{"priceId":14,"serviceId":1,"price":70.0000,"startDate":"6\/14\/2010 12:00:00 AM","endDate":"12\/31\/2011 12:00:00 AM","updatedBy":null,"updateDate":null},{"priceId":142,"serviceId":1,"price":70.0000,"startDate":"6\/14\/2010 12:00:00 AM","endDate":"12\/31\/2011 12:00:00 AM","updatedBy":null,"updateDate":null}]}}
答案 0 :(得分:1)
你正在使用JsonStore&将读者对象传递给它但jsonStore获取JsonReader&的配置。创造一个读者本身。你有两个选择:
Ext.data.Store
用于V2020.dsPricing
解决方案1:
var url = "http://localhost/r.json"; objPricingReturn = {serviceId:10}; function PricingJsonReader() { var pricingReaderObject = new Ext.data.JsonReader({ root: 'GetServicePriceByIdResult.ServicePricing', fields: [{ name: 'priceId', type: 'int' }, { name: 'serviceId', type: 'int' }, { name: 'price', type: 'float' }, { name: 'startDate', type: 'date', dateFormat: 'n/j/Y' }, { name: 'endDate', type: 'date', dateFormat: 'n/j/Y' }, { name: 'updatedBy', type: 'string' }, { name: 'updateDate', type: 'date', dateFormat: 'n/j/Y' }] }) return pricingReaderObject; } V2020 = {}; V2020.dsPricing = new Ext.data.Store({ proxy: new Ext.data.HttpProxy({ method: 'POST', url: url, headers: {"Content-Type": "application/json; charset=utf-8"}, jsonData: Ext.util.JSON.encode({ serviceId: objPricingReturn.serviceId }) }), reader: PricingJsonReader() }); V2020.dsPricing.on('loadexception', function(obj, options, response, err) { Ext.MessageBox.show({ title: 'Error', msg: url + ' POST method fail...ErrorCode:' + response.status, buttons: Ext.MessageBox.OK, icon: Ext.MessageBox.ERROR }); }); V2020.dsPricing.load({ callback: function(records, o, s) { if (!s) Ext.MessageBox.show({ title: 'Error', msg: ' Failed to load pricing data', buttons: Ext.MessageBox.OK, icon: Ext.MessageBox.ERROR }); } });