Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/extjs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在extjs中在内存中加载ajax响应_Ajax_Extjs_Extjs4 - Fatal编程技术网

如何在extjs中在内存中加载ajax响应

如何在extjs中在内存中加载ajax响应,ajax,extjs,extjs4,Ajax,Extjs,Extjs4,如何在extjs中加载内存中的数据。通过使用ajax响应。ajax响应提供json数据。 当我尝试加载到分页网格时,它没有显示任何内容。你能想到谁吗?这对我完全有帮助 var itemsPerPage = 10; // set the number of items you want per page // i am creating a store to load data into memory var store = Ext.create('Ext.data.Store',

如何在extjs中加载内存中的数据。通过使用ajax响应。ajax响应提供json数据。 当我尝试加载到分页网格时,它没有显示任何内容。你能想到谁吗?这对我完全有帮助

var itemsPerPage = 10;   // set the number of items you want per page

//  i am creating a store to load data into memory    
var store = Ext.create('Ext.data.Store', {    
    autoLoad: true,
    fields:['id','name', 'email'],
    pageSize: itemsPerPage, // items per page
    proxy: {
        type:'memory',
        enablePaging: true,
        reader: {
            type: 'json',
            root: 'users',
            successProperty: 'success'
         }
    }         
});

// i am creating a ajax request to get json data
Ext.Ajax.request({
    url: 'app/data/users.json',     
    success: function(resp) {            
       var result = resp.responseText;
       store.loadRawData(result);
    },        
});

// to view data in store 
Ext.define('AM.view.user.list' ,{
    extend: 'Ext.grid.Panel',
    alias: 'widget.userlist',
    title: 'All Users',
    initComponent: function() {
        Ext.create('Ext.grid.Panel', {
            title: 'My Test Demo',
            store:store,
            columns: [
                { header: 'ID',  dataIndex: 'id' }, 
                { header: 'Name',  dataIndex: 'name' },
                { header: 'Email', dataIndex: 'email', flex: 1 }
              ],
            width: 350,
            height: 280,
            dockedItems: [{
                xtype: 'pagingtoolbar',
                store:store,   // same store GridPanel is using
                dock: 'bottom',
                displayInfo: true,
                pageSize:5,       
            }],
            renderTo: Ext.getBody()             
        });

        this.callParent(arguments);
    }
});
我的json数据如下所示

{
"success": true,
"users": [
    {"id": 1, "name": 'Ed',    "email": "ed@sencha.com"},
    {"id": 2, "name": 'Tommy', "email": "tommy@sencha.com"},

      {"id": 3, "name": 'Tommy', "email": "tommy@sencha.com"},

      {"id": 4, "name": 'Tommy', "email": "tommy@sencha.com"},

      {"id": 5, "name": 'Tommy', "email": "tommy@sencha.com"},

    {"id": 11, "name": 'Ed',    "email": "ed@sencha.com"},
    {"id": 12, "name": 'Tommy', "email": "tommy@sencha.com"},

      {"id": 13, "name": 'Tommy', "email": "tommy@sencha.com"},

      {"id": 14, "name": 'Tommy', "email": "tommy@sencha.com"},

      {"id": 15, "name": 'Tommy', "email": "tommy@sencha.com"},


        {"id": 21, "name": 'Ed',    "email": "ed@sencha.com"},
    {"id": 22, "name": 'Tommy', "email": "tommy@sencha.com"},

      {"id": 23, "name": 'Tommy', "email": "tommy@sencha.com"},

      {"id": 24, "name": 'Tommy', "email": "tommy@sencha.com"},

      {"id": 25, "name": 'Tommy', "email": "tommy@sencha.com"},


]

}除非您有特殊需要,否则您可能不应该直接使用内存代理。使用JSON将数据加载到存储中是一项非常常见的任务,通过Ajax代理可以很好地实现自动化

放下您的手册
Ext.Ajax.request()
调用并将您的
代理更改为Ajax代理:

proxy: {
    type: 'ajax',
    url : 'app/data/users.json'
    reader: {
        type: 'json',
        root: 'users',
        successProperty: 'success'
    }
}

另外,在
initComponent
方法中调用
create()
是不正确的。我觉得您应该阅读ExtJS4应用程序架构,并开始使用ExtJS框架。当我刚开始使用ExtJS4时,这些很好的概述帮助了我。(如果我读错了,你使用的是不同的ExtJS版本,当然,请阅读与你选择的版本相对应的教程和概述)

我在ExtJS中使用分页,这就是我需要的内存。因此,使用ajax可以很好地加载数据,但数据不会加载到内存中。传统上,分页是在服务器端完成的,以防止不适当的服务器负载,但是如果您设置为加载所有数据并在客户端分页,那么您可能只需要将加载调用更改为引用数据根:
store.loadRawData(result.users)
是否有办法将ajax响应加载到extjs代理中的内存中