Javascript ExtJS-错误状态';原型&x27;是否为null或不是对象
我在调试和获得解决方案时遇到了一些问题 我的数据被正确地返回给我,但当我在“loadexception”函数上设置断点时,它向我抛出了TypeError。以下是错误: 描述-“'prototype'为空或不是对象” 消息-“'prototype'为空或不是对象” 名称-“类型错误” 电话号码--2146823281 因此,即使我的数据恢复正常,我的callbox消息框也总是出现错误Javascript ExtJS-错误状态';原型&x27;是否为null或不是对象,javascript,wcf,extjs,Javascript,Wcf,Extjs,我在调试和获得解决方案时遇到了一些问题 我的数据被正确地返回给我,但当我在“loadexception”函数上设置断点时,它向我抛出了TypeError。以下是错误: 描述-“'prototype'为空或不是对象” 消息-“'prototype'为空或不是对象” 名称-“类型错误” 电话号码--2146823281 因此,即使我的数据恢复正常,我的callbox消息框也总是出现错误 V2020.dsPricing = new Ext.data.JsonStore({ proxy:
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;
}
回答(我想这就是你想要的)
您正在使用JsonStore&向它传递一个reader对象,但是JsonStore获取JsonReader的配置并创建一个reader本身。您有两种选择:
V2020.dsPricing
令人惊叹的。谢谢你的澄清。我没意识到这是在创造一个读者。 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 }); } });