试图加载外部存储与JSON数据来自AJAX请求返回错误加载、错误、数据、JSON

2023-09-10 20:58:05 作者:是沧桑就是

在尝试加载和外部存储与分机4.0.7。

Am attempting to load and Ext Store with Ext 4.0.7.

这是返回一个的对象不支持此属性或方法的错误,当我呼吁商店在AJAX请求成功回调loadRawData方法。

It is returning an Object doesn't support this property or method error when i call the loadRawData method on the store in the success callback of the AJAX request.

下面是数据我加载:

{
    "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
    } 
    ]
}

这是店里code和Ajax请求:

This is the store code and ajax request:

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

不是很明白为什么这是返回一个错误?

Can't quite see why this is returning an error?

推荐答案

正如我的评论,你鸵鸟政策需要pagingmemory店。你需要的是一个Ajax店,因为pagingstore是允许分页数据必须在内存中,但没有任何理由用它看您的要求。

As in my comment, you don´t need a pagingmemory store. What you need is an ajax store because the pagingstore is for allowing pagination with data you have in memory but there is no reason to use it seeing your requirement.

所以,如果你使用一个标准的AJAX代理,你将能够加载它以正常方式(使用.load()方法)。然后,当你需要的从服务器添加详细记录你什么,你所要做的仅仅是再次调用加载方法,但用在 addRecords 选项。

So if you use an standard ajax proxy, you will be able to load it in the normal way (using the .load() method). Then, when you need to add more record from the server you what you have to do is just call the load method again but with the addRecords option.

例如(未经测试样本):

For example (untested sample):

// 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
});