extjs - 应用程序启动时不应加载具有自动加载功能的存储 [英] extjs - Store with autoload true should not load on application launch

查看:28
本文介绍了extjs - 应用程序启动时不应加载具有自动加载功能的存储的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网格链接到一个带有 autoLoad: true 的商店.问题是商店在应用程序启动时加载,即使视图是在稍后通过菜单访问时才创建的.

I have a grid linked to a store with autoLoad: true. The problem is that the store gets loaded on application launch, even if the view is created only later when accessed through a menu.

我已经在 Application.js 和视图中引用了商店,但我没有明确说明商店和视图.

I have referenced the store in Application.js and in the view, but I'm not instatiating explicitly neither the store nor the view.

我不知道如何实现仅在视图需要时才加载商店.

I don't know how to achieve that the store is loaded only when needed by the view.

  • 如果我设置了 autoLoad: true,商店会在应用程序启动时加载.
  • 如果我设置了 autoLoad: false,商店根本不会被加载.
  • If I set autoLoad: true, the store gets loaded on application launch.
  • If I set autoLoad: false, the store doesn't get loaded at all.

我知道这是非常基本的,但到目前为止我还是卡住了.

I know this is pretty basic, but I'm stuck so far.

这里是所有相关代码供参考:
应用程序/商店/Owners.js

Here is all the relevant code for reference:
app/store/Owners.js

Ext.define('Mb.store.Owners', {
    extend: 'Ext.data.Store',
    model: 'Mb.model.Owner',
    autoLoad: true,
    proxy: {
        ...
});

应用程序.js

Ext.define('Mb.Application', {
    name: 'Mb',
    extend: 'Ext.app.Application',
    models: [
        'Owner'
    ],
    stores: [
        'Owners'
    ],
    ...

app/view/Owners.js

app/view/Owners.js

Ext.define('Mb.view.winbiz.Owners', {
    extend: 'Ext.grid.Panel',
    alias: 'widget.test-gridPanel',
    store: 'winbiz.Owners',
    columns: [{
    ...

视图在控制器中实例化:

The view is instantiated in the controller:

Ext.define('Mb.controller.Winbiz', {
    extend: 'Ext.app.Controller',
    views: [
        'Owners'
    ],
    init: function(){
        this.control({
            'menu #test': {click: this.onMenuTest},
        })
    },
    onMenuTest: function(){
        this.getController('Main').addToMainTab('test-gridPanel');
    },

推荐答案

您可以添加 render 处理程序来查看它会调用 store load 方法并禁用 autoLoad.

You can add render handler to view which will call store load method and disable autoLoad.

示例监听器:

Ext.define('Mb.view.winbiz.Owners', {
    extend: 'Ext.grid.Panel',
    [...],

    initComponent: function(){
        this.callParent();
        this.on('render', this.loadStore, this);
    },

    loadStore: function() {
        this.getStore().load();
    }
});

这篇关于extjs - 应用程序启动时不应加载具有自动加载功能的存储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆