【发布时间】:2012-12-04 04:14:54
【问题描述】:
我正在尝试使用 Ext 4.0.7 加载和 Ext Store。
当我在 AJAX 请求的成功回调中调用 store 上的 loadRawData 方法时,它返回一个 对象不支持此属性或方法错误。
这是我正在加载的数据:
{
"data": [
{
"id": 1,
"source": "1445261",
"target": "1437043",
"sourceType": "user",
"redirectUrl": "http://www.google.co.uk",
"message": "this is a notification message",
"targetType": "user",
"messageType": "notification",
"sentDate": "1354758001",
"notificationType": "notification",
"parameters": "null",
"read": "false",
"readDate": 1354758001
},
{
"id": 2,
"source": "1445261",
"target": "1437043",
"sourceType": "user",
"redirectUrl": "http://www.google.co.uk",
"message": "this is a notification message",
"targetType": "user",
"messageType": "notification",
"sentDate": "1354758001",
"notificationType": "notification",
"parameters": "null",
"read": "false",
"readDate": 1354758001
},
{
"id": 3,
"source": "1445261",
"target": "1437043",
"sourceType": "user",
"redirectUrl": "http://www.google.co.uk",
"message": "this is a notification message",
"targetType": "user",
"messageType": "notification",
"sentDate": "1354758001",
"notificationType": "notification",
"parameters": "null",
"read": "false",
"readDate": 1354758001
}
]
}
这是商店代码和ajax请求:
var infoStagingStore = Ext.create('Ext.data.Store', {
model: 'SCB.RMWB.InfoBar.Model.Message',
storeId: 'Staging',
autoLoad: false,
pageSize: 10,
proxy: {
type: 'pagingmemory',
reader: {
type: 'json',
root: 'data'
}
},
listeners: {
load: function(){
console.log('loaded');
}
}
});
Ext.Ajax.request({
url: '/rmwb/resources/js/app/infoBar/data/data.json',
timeout: 60000,
method: 'GET',
scope: this,
params: '',
success: function(resp) {
console.log(resp.responseText);
var store = Ext.data.StoreManager.lookup('Staging');
store.loadRawData(resp.responseText, true);
},
failure: function(resp, opts) {
},
callback: function(options, success, resp) {
}
});
不太明白为什么会返回错误?
【问题讨论】:
-
不使用 ajax 代理有什么好的理由吗?你为什么以这种方式加载商店?我的意思是,pagingmemory 用于我们在内存中的分页数据,但是......您正在从服务器获取数据。
-
公平点。但是如何在从服务器加载页面时将数据加载到分页内存存储中?我是否需要将数据从上述存储加载到后续的分页内存存储。要求是从服务器中提取历史数据,然后通过轮询接受新数据,然后将其添加到分页内存存储中。