最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - extjs 4.2.1 - storemanager.lookup returning undefined - Stack Overflow

programmeradmin2浏览0评论

I have a really simple program where I try to hook up a store to an Ext.panel.Grid. I can't seem to get the Ext.data.StoreManager.lookup() in my Main.js call to return anything other than 'undefined.' Ext.create('LeaveRequestGrid.store.LeaveRequestStore') seems to work (with some warnings), but I want to know what the correct way is to do this.

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}
            ]
        }
    ]
});

I have a really simple program where I try to hook up a store to an Ext.panel.Grid. I can't seem to get the Ext.data.StoreManager.lookup() in my Main.js call to return anything other than 'undefined.' Ext.create('LeaveRequestGrid.store.LeaveRequestStore') seems to work (with some warnings), but I want to know what the correct way is to do this.

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}
            ]
        }
    ]
});
Share Improve this question edited Jan 2, 2014 at 6:35 tereško 58.5k25 gold badges100 silver badges150 bronze badges asked Jan 1, 2014 at 17:34 Android NoobAndroid Noob 3,3414 gold badges37 silver badges60 bronze badges 3
  • Have you tried defining store using string name of store in grid? ie. store:'LeaveRequestStore' – weeksdev Commented Jan 1, 2014 at 18:11
  • Additionally stores are usually defined on the app? is your app named LeaveRequestGrid? – weeksdev Commented Jan 1, 2014 at 18:53
  • The app is named LeaveRequestGrid. The store name is LeaveRequestStore. – Android Noob Commented Jan 2, 2014 at 1:49
Add a ment  | 

1 Answer 1

Reset to default 6

I figured it out.

You define your stores: ['LeaveRequestStore'] in Application.js. Then, in Main.js (or whatever file your gridpanel is in), you simple say store: 'LeaveRequestStore'. That's it. No need to call Ext.getStore('LeaveRequestStore') or Ext.data.StoreManager.lookup('LeaveRequestStore'). when referencing a store in the store property.

发布评论

评论列表(0)

  1. 暂无评论