【问题标题】:ExtJS 4 - Display Grid using remote json storeExtJS 4 - 使用远程 json 存储显示网格
【发布时间】:2014-07-28 09:51:18
【问题描述】:

我是 ExtJS 4 的新手。我正在尝试显示一个从远程存储中获取结果的结果列表,但没有太多成功。

下面是视图文件

Ext.define('Crm.view.CompanyList', {
    extend: 'Ext.grid.Panel',
    alias: 'widget.companyList',
    store : 'Crm.store.Companies',
    title : 'Company List',

    initComponent: function(){
        this.columns = [ {
            text : 'ID',
            width : 150,
            dataIndex : 'id'
        }, {
            text : 'LastName',
            width : 150,
            sortable : false,
            hideable : false,
            dataIndex : 'lastName'
        }, {
            text : 'First Name',
            width : 150,
            sortable : false,
            hideable : false,
            dataIndex : 'firstName'
        }, {
            text : 'Street',
            flex : 1,
            sortable : false,
            hideable : false,
            dataIndex : 'street'
        } ];
        this.dockedItems = [ {
            xtype : 'pagingtoolbar',
            store : 'Companies',
            dock : 'bottom',
            displayInfo : true
        } ];
        this.callParent();
    }
});

下面是模型

Ext.define('Crm.model.Company',{
    extend  : 'Ext.data.Model',
    fields  : [
        {name:'id',type:'string'},
        {name:'lastName',type:'string'},
        {name:'firstName',type:'string'},
        {name:'street',type:'string'}
    ]
});

这就是商店的定义

Ext.define('Crm.store.Companies', {
    extend: 'Ext.data.Store',
    requires: 'Crm.model.Company',
    model: 'Crm.model.Company',
    autoLoad: {start: 0, limit: 5},
    pageSize: 5,
    remoteSort: true,
    sorters: [{
        property : 'lastName',
        direction: 'asc'
    }],
    proxy: {
        type: 'jsonp',
        url : 'http://extjsinaction.com/crud.php?model=Employee&method=READ',
        reader: {
            type: 'json',
            root: 'data',
            idProperty      : 'id',
            //  successProperty : 'meta.success',
            totalProperty   : 'meta.total'
        }
    }
});

最后是预期在浏览器中呈现网格的 HTML 文件

    <html>
    <head>
    <link rel="stylesheet" type="text/css" href="http://cdn.sencha.io/ext-4.2.0-gpl/resources/css/ext-all.css">
    <script type="text/javascript" src="http://cdn.sencha.io/ext-4.2.0-gpl/ext-all-dev.js"></script>
    <script type="text/javascript" src="Crm/view/CompanyList.js"  ></script>
    <script type="text/javascript" src="Crm/model/Company.js"  ></script>
    <script type="text/javascript" src="Crm/store/Companies.js"  ></script>
    </head>
    <body>
    <script type="text/javascript" >
    Ext.onReady(function() {
    Ext.create('Crm.view.CompanyList', {
    });
    );
    </script>
    </body>
    </html>

当我在浏览器中运行时,我在浏览器控制台中收到以下错误

Uncaught TypeError: Cannot read property 'buffered' of undefined ext-all-dev.js:145555

谁能指导我解决这个问题。谢谢。

【问题讨论】:

    标签: javascript ajax extjs extjs4.2


    【解决方案1】:

    您的代码失败的主要原因是网格没有商店。您将商店配置为字符串(类名),但这种方法只有在 Ext 为您创建商店时将 MVC 与 Ext.Application 一起使用时才有效。

    您可以通过在网格的initComponent 中创建商店来完成上述工作:

    this.store = Ext.create('Crm.store.Companies', {});
    

    从长远来看,我建议使用 Sencha Cmd 和 MVC(用于 Ext 5 的 MVVM)架构。

    【讨论】:

      猜你喜欢
      • 2011-09-01
      • 1970-01-01
      • 2011-08-18
      • 2020-05-08
      • 2012-12-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多