【问题标题】:TreeStore: different behaviour beetween autoLoad configuration and load() functionTreeStore:autoLoad 配置和 load() 函数之间的不同行为
【发布时间】:2016-03-16 20:22:51
【问题描述】:

fiddle 中的测试用例正在使用autoLoad: true,但使用autoLoad: false(第 86 行),在 TreePanel beforerender 事件的第 161 行调用的 load() 函数不会加载数据...

对于(非树)面板,我总是将 autoLoad 设置为 false 并在 GridPanel 的渲染上加载存储,它工作得很好。我这样做是为了防止在开始时加载所有商店(有时还设置过滤器)。
商店的beforeload 事件防止双重加载。

我对这个 TreeStore 的错在哪里?找了好久没有任何结果的解决方案...

【问题讨论】:

标签: extjs5


【解决方案1】:

Ext JS 4 中也有类似的问题,这里解释了 ExtJS 4. Hidden treepanel with autoload false

我在你的小提琴中所做的是我刚刚添加了以下内容

  autoLoad: false,
  root:{
    //expanded: true, // optional
    children: []
  }

到您的商店配置中的91 行。一切都很神奇。

【讨论】:

  • root: {expanded: true} 是与 qmat 相同的非工作解决方案...此设置间接将 autoLoad 设置为 true。
  • @Michel 实际上重要的是 children: [] 属性,expanded 也可能是假的。
  • @Michel 这里正在工作小提琴fiddle.sencha.com/#fiddle/1873(我已经推迟到beforerender 中的store.load)
【解决方案2】:

我想我已经解决了你的问题。

为您的 TreeStore 使用 root 属性。

/*
 * Store
 */
Ext.define('Chronos.store.Clockings', {
    extend  : 'Ext.data.TreeStore',
    requires: [
        //'Chronos.store.Session'
    ],
    model       : 'Chronos.model.Presence',
    autoLoad    : false, //true, // false,
    //autoSync    : true, // DEBUG
    sortOnLoad  : false,
    pageSize    : 0,
    remoteFilter: true,

    root: {
       id: 'id',
       expanded: true
    },

    listeners: {
        load: function(treestore, records, success) {
            console.log(Date(), 'clockings loaded: ', success, treestore);
        },
        beforeload: function (treestore) {            
            if(treestore.isLoading()) return false;        
        }
    }
});

希望这就是你要找的东西!

【讨论】:

  • 不幸的是不是因为It's important to note that Tree Stores will load regardless of autoLoad's value if expand is set to true on the root node. 根据the documentation。这意味着您的代码将 autoLoad 间接设置为 true,这不是我想要的。
猜你喜欢
  • 2018-08-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-02-01
  • 2016-05-14
  • 2014-11-01
相关资源
最近更新 更多