【问题标题】:extjs 4.2.1 - storemanager.lookup returning undefinedextjs 4.2.1 - storemanager.lookup 返回未定义
【发布时间】:2014-01-01 17:34:22
【问题描述】:

我有一个非常简单的程序,我尝试将商店连接到 Ext.panel.Grid。我似乎无法在 Main.js 调用中获得 Ext.data.StoreManager.lookup() 来返回除“未定义”之外的任何内容。 Ext.create('LeaveRequestGrid.store.LeaveRequestStore') 似乎有效(带有一些警告),但我想知道正确的方法是什么。

LeaveRequestStore.js:

Ext.define('LeaveRequestGrid.store.LeaveRequestStore', {
    extend: 'Ext.data.Store',
    storeId: 'leaveRequestStore',
    autoLoad: true,
    fields: [
        'dateCreated',
        'startDate',
        'endDate',
        'leaveType',
        'totalHours',
        'approver',
        'status'
    ],
    data: {
        'leaveRequest' : [
            {   
                'dateCreated': '12/01/2013' ,
                'startDate' : '01/01/2014',
                'endDate' : '01/02/2014' ,
                'leaveType' : 'Paid Admin Leave' ,
                'totalHours' : 16 ,
                'approver' : 'John Smith' ,
                'status' : 'Pending' 
            },
            {   
                'dateCreated': '01/01/2014' ,
                'startDate' : '02/01/2014',
                'endDate' : '02/02/2014' ,
                'leaveType' : 'Vacation' ,
                'totalHours' : 16 ,
                'approver' : 'John Smith' ,
                'status' : 'Pending' 
            },
            {   
                'dateCreated': '02/01/2013' ,
                'startDate' : '03/01/2014',
                'endDate' : '03/02/2014' ,
                'leaveType' : 'Paid Time Off' ,
                'totalHours' : 16 ,
                'approver' : 'John Smith' ,
                'status' : 'Pending' 
            }
        ]
    },
    proxy: {
        type: 'memory',

        reader: {
            type: 'json',
            root: 'leaveRequest'
        }
    }
})

Main.js:

Ext.define('LeaveRequestGrid.view.Main', {
    extend: 'Ext.container.Container',
    requires:[
        'Ext.grid.Panel',
        'LeaveRequestGrid.store.LeaveRequestStore'
    ],

    xtype: 'app-main',

    layout: {
        type: 'fit'
    },

    items: [
        {
            xtype: 'grid',
            title: '<div style="text-align:center">Leave Requests</div>',
            //store: Ext.create('LeaveRequestGrid.store.LeaveRequestStore'),
            store: Ext.data.StoreManager.lookup('leaveRequestStore'),
            columns: [
                {text: 'Date Created', dataIndex: 'dateCreated', flex: 1},
                {text: 'Start Date', dataIndex: 'startDate', flex: 1},
                {text: 'End Date', dataIndex: 'endDate', flex: 1},
                {text: 'Leave Type', dataIndex: 'leaveType', flex: 1},
                {text: 'Total Hours', dataIndex: 'totalHours', flex: 1},
                {text: 'Approver', dataIndex: 'approver', flex: 1},
                {text: 'Status', dataIndex: 'status', flex: 1}
            ]
        }
    ]
});

【问题讨论】:

  • 您是否尝试过在网格中使用string 商店名称来定义商店? IE。 store:'LeaveRequestStore'
  • 另外商店通常在应用程序上定义?你的应用是 LeaveRequestGrid 吗?
  • 应用名为 LeaveRequestGrid。商店名称是 LeaveRequestStore。

标签: javascript extjs extjs4.2


【解决方案1】:

我想通了。

您在Application.js 中定义您的stores: ['LeaveRequestStore']。然后,在Main.js(或您的gridpanel 所在的任何文件)中,您简单地说store: 'LeaveRequestStore'。就是这样。在 store 属性中引用商店时无需调用 Ext.getStore('LeaveRequestStore')Ext.data.StoreManager.lookup('LeaveRequestStore').

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-18
    • 1970-01-01
    • 1970-01-01
    • 2019-11-17
    • 1970-01-01
    相关资源
    最近更新 更多