【问题标题】:Hard coded data in global store does not show in extjs grid全局存储中的硬编码数据未显示在 extjs 网格中
【发布时间】:2015-10-10 02:10:11
【问题描述】:

我有一个 extjs 全局存储,是否已使用字段和数据进行硬编码:

Ext.define('Registration.store.SavedSessions',{
    extend: 'Ext.data.Store',
    storeId: 'savedsessions',

    fields:[
    "id",
    "title",
    "dateStart"
    ],

    data: [
        {
            id: 1,
            title: 'test',
            dateStart: new Date()
        }
    ]

});

全局存储通过 Application.js 文件注册:

Ext.define('Registration.Application', {
    extend: 'Ext.app.Application',

    name: 'Registration',

    stores: [
        'SavedSessions'
    ],
    ...

我还有一个网格,我正在尝试将商店加载到:

Ext.define("Registration.view.cart.savedsessions.SavedSessions",{
    extend: "Ext.grid.Panel",

    xtype: 'savedsessions',

    store: Ext.data.StoreManager.lookup('savedsessions'),

    columns:[
        {
            text: 'Date',
            dataIndex: 'dateStart'
        },
        {
            text: 'Title',
            dataIndex: 'title',
            flex: 1
        }
    ]
});

查看文档,这一切看起来都是正确的。我遇到的问题是商店没有加载。

当我打开 javascript 控制台并计算网格存储中的记录数时,我得到 0:

考虑到数据是硬编码到存储中的,我完全不确定这是怎么发生的。

另外,当我直接从 javascript 控制台获取商店时,我可以获得硬编码数据:

我在这里错过了什么?

【问题讨论】:

    标签: javascript extjs extjs6-classic


    【解决方案1】:

    为什么要使用StoreManager 来获取store?只需使用storeId

    store: 'savedsessions',
    

    【讨论】:

    • 谢谢。那肯定解决了。我匆匆忙忙经过first example they show in the docs for the grid。我还没有使用很多全球商店(我主要在我的视图模型中使用商店),出于某种原因,我认为 storeId 是您使用 storemanager 查找商店所需的。感谢您指出它不是必需的。也就是说,你知道为什么当通过 store manager 拉取时它会得到 store 而不是硬编码数据吗?
    • 这可能有几个原因。它可能是加载视图和存储的顺序,框架如何加载和实例化视图和其他对象的方式。该框架首先加载所有类声明,然后仅在需要时实例化这些类。因此,您的视图声明已经加载,在商店实例化之前是猜测。请记住,您永远不会在视图声明中使用对象。不要使用管理器(我从不使用它们),不要使用new 或其他任何东西。 sencha.guru/2015/07/29/instances-on-prototype-are-bad
    • 明白了。感谢您的额外说明,并一如既往地感谢您的帮助。
    猜你喜欢
    • 2012-12-28
    • 2020-05-08
    • 2012-08-22
    • 1970-01-01
    • 1970-01-01
    • 2013-08-26
    • 2012-05-05
    • 1970-01-01
    • 2013-12-22
    相关资源
    最近更新 更多