从extjs中的ajax响应将数据加载到内存中

时间:2015-01-05 10:17:10

标签: extjs

我的json数据看起来像这样

//
//var data = {
//      
//
//      
//      
//     "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"},
//       
//         
//     ]
//  }       
//           







// this my store in extjs


var store = Ext.create('Ext.data.Store', {
    model: 'AM.model.User',
        pageSize : 10,

        autoLoad: true,
       data:data,

        proxy: {
            type: 'memory',

            enablePaging: true,
            reader: {
                type: 'json',
                root: 'users',
                 totalProperty : 'total'
            }
        },








    });

// ajax request to call json data in json file

Ext.Ajax.request({
       url: 'app/data/users.json',

       success: function(response, opts) {
          var obj = response.responseText;


          store.loadData(resp.responseText, true); 

       },
       failure: function(response, opts) {
          console.log('server-side failure with status code ' + response.status);
       }
    });



// this is my view .

Ext.define('AM.view.user.List' ,{
    extend: 'Ext.grid.Panel',
    alias: 'widget.userlist',

    title: 'All Users',





    initComponent: function() {

        Ext.create('Ext.grid.Panel', {
          title: 'Column Demo',
          store:store,
          columns: [
         {header: 'ID',  dataIndex:'id',flex:1},
              {header: 'Name',  dataIndex:'name',flex:1},
              {text: 'Email',  dataIndex:'email',flex:1},

          ],

         renderTo:'example-grid',
         width: 350,
         height: 285,
      dockedItems: [{
          xtype: 'pagingtoolbar',
          store: store,   // same store GridPanel is using
          dock: 'bottom',
          pageSize: 10,
          prependButtons: true,
          displayInfo: true
      }],






          renderTo: Ext.getBody()
        });


        store.loadPage(1);
      this.callParent(arguments);
  }



});

我将使用分页。因为我需要json数据。我从ajax response.how获取json数据以将ajax响应json数据加载到内存中。谁能帮我?我正在以正确的方式或错误的方式进行我不会有任何人帮助我

1 个答案:

答案 0 :(得分:0)

resp.responseText返回一个纯字符串。 改为使用JSON.parse(resp.responseText)。