1

我正在尝试使用 Ext 4.0.7 加载和 Ext Store。

当我在 AJAX 请求的成功回调中调用 store 上的 loadRawData 方法时,它返回一个Object 不支持此属性或方法错误。

这是我正在加载的数据:

{
    "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) {
    }
}); 

不太明白为什么这会返回错误?

4

2 回答 2

3

看到你已经将你的商店分配给一个名为的变量infoStagingStore,你不能只在你的 ajax 调用中引用那个目录吗?

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');
        infoStagingStore.loadRawData(resp.responseText, true);
    },
    ...
于 2012-12-17T09:14:15.517 回答
3

正如我的评论,您不需要分页内存存储。您需要的是 ajax 存储,因为 pagingstore 用于允许对内存中的数据进行分页,但没有理由使用它来满足您的要求。

因此,如果您使用标准的 ajax 代理,您将能够以正常方式加载它(使用 .load() 方法)。然后,当您需要从服务器添加更多记录时,您只需再次调用 load 方法,但使用addRecords选项。

例如(未经测试的样本):

// load store with historical data
infoStagingStore.load(); 

// load more records to the store from a different resource
infoStagingStore.load({
    url: '/rmwb/resources/js/app/infoBar/data/data.json',
    addRecords: true
});
于 2012-12-17T13:02:38.710 回答