试图加载分机存储与JSON数据从AJAX请求返回错误(Attempting to load Ext

2019-10-17 11:44发布

我试图加载和外置存储与分机4.0.7。

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

这里是我的加载数据:

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

不能完全明白为什么这是返回一个错误?

Answer 1:

正如我的评论,你鸵鸟政策需要pagingmemory店。 你需要的是一个AJAX店因为pagingstore是允许与数据分页内存中已经有了,但没有理由使用它看到您的要求。

所以,如果你使用一个标准的AJAX代理,你将能够加载它以正常方式(使用.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
});


Answer 2:

看到在您指定的商店一个变量叫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);
    },
    ...


文章来源: Attempting to load Ext store with JSON data from AJAX request returns error