【发布时间】:2011-10-30 11:47:40
【问题描述】:
我试图通过处理各种可能发生的异常来使我的代码更加健壮。一个可能是 Json Web 请求上的 404 异常。当 Json 请求收到 404 异常时,似乎没有调用 store.load 的回调方法。
代码:
Ext.regModel('Activiteit', {
fields: [
{ name: 'id', type: 'int' },
{ name: 'ServerId', type: 'int', mapping: 'Id' },
{ name: 'Title', type: 'string' },
{ name: 'Description', type: 'string' },
],
});
Ext.regApplication({
name: 'App',
launch: function () {
console.log('launch');
var ajaxActiviteitStore = new Ext.data.Store({
model: "Activiteit",
storeId: 'ajaxActiviteitStore',
proxy: {
type: 'ajax',
url: '/senchatest/Activiteit/Gett/',
reader: {
type: 'json',
root: 'activiteiten'
}
}
});
ajaxActiviteitStore.load(function (records, operation, success) {
//the operation object contains all of the details of the load operation
console.log(success);
});
}
});
这会导致 sencha-touch-debug.js 的第 7212 行出现“未捕获的类型错误:无法读取未定义的属性 'length'”异常。我使用的是 sencha touch 1.1.0 版。
堆栈跟踪:
Uncaught TypeError: Cannot read property 'length' of undefined
Ext.data.Store.Ext.extend.loadRecords sencha-touch-debug.js:7212
Ext.data.Store.Ext.extend.onProxyLoad sencha-touch-debug.js:7024
(anonymous function) sencha-touch-debug.js:8742
Ext.data.Connection.Ext.extend.onComplete sencha-touch-debug.js:17566
Ext.data.Connection.Ext.extend.onStateChange sencha-touch-debug.js:17513
(anonymous function) sencha-touch-debug.js:3421
我在这里做错了什么?
我通过向代理添加一个侦听“异常”事件的侦听器找到了解决方法,但我更希望调用存储加载的回调函数。我做错了什么,还是这是默认行为?
谢谢,
砂光机
【问题讨论】:
标签: exception-handling sencha-touch extjs