首页 > 解决方案 > sencha extjs 在 storemanager 完成加载后运行?

问题描述

在开发应用程序时,我在应用程序启动时运行一些代码:

Ext.application({
    extend: 'TestApp.Application',

    name: 'TestApp',

    requires: [
        'TestApp.*'
    ],

    // The name of the initial view to create.
    launch: async function () {
        const store_org = Ext.getStore('Organizations');
        const store_event = Ext.getStore('Events');
        //more stuff here
    }
});

两家商店都定义明确:

Ext.define('TestApp.store.Organization', {
    extend: 'Ext.data.Store',
    storeId: 'Organizations',
    alias: 'store.organizations',

    model: 'TestApp.model.Organization',
    autoLoad: true,

    pageSize: 0,


    proxy: {
        type: 'ajax',
        url: TestApp.util.Config.getHost() + '/organization/get-organizations',
        withCredentials: true,
        reader: {
            type: 'json',
            rootProperty: '',
        },
    },
});

但是我确实注意到,在启动该Ext.getStore()函数时,总是返回undefined任何商店。有什么办法可以将其“延迟”到 storemanager 已完全加载并且这些商店不再返回 undefined 的程度?(商店本身不会充满数据......)。

标签: javascriptextjsstoreextjs6-modern

解决方案


只需将其添加到 Ext.application 类或 TestApp.application (更好)

stores:['TestApp.store.Organization'],

这是您所有商店的数组,因此如果您需要添加更多商店,只需使用逗号并写入新文件的类路径名

这是一个工作示例小提琴


推荐阅读