EXTJS--treestore getCount()方法返回未定义的,是否有其他方法检查存储是否已加载?

EXTJS--treestore getCount()方法返回未定义的,是否有其他方法检查存储是否已加载?,extjs,Extjs,我有一个卡布局和卡上的“激活”事件,我加载商店。为了防止每次激活该卡时加载存储,我检查getCount==0,如果为true,则加载存储: handleActivateGrid: function(){ if(this.myTreeGrid().getStore().getCount() == 0){ this.myTreeGrid().getStore().load(); } 我在代码的其他地方也使用了同样的方法,效果非常好,唯一的区别是在这个例子中它是Ext.

我有一个卡布局和卡上的“激活”事件,我加载商店。为了防止每次激活该卡时加载存储,我检查getCount==0,如果为true,则加载存储:

handleActivateGrid: function(){

    if(this.myTreeGrid().getStore().getCount() == 0){
      this.myTreeGrid().getStore().load();
    }
我在代码的其他地方也使用了同样的方法,效果非常好,唯一的区别是在这个例子中它是Ext.data.TreeStore

我进行了调试,getCount()未定义,即使在加载存储之后也是如此

我是否可以使用其他方法来实现上述功能

谢谢

编辑:刚刚检查了文档,getCount()不是Ext.data.TreeStore的方法,因此解释了刚刚尝试了这段代码

myTreeGrid().getStore().getRootNode().getChildAt(0) == undefined
由单个根节点和子节点组成

要查看根节点下是否有节点,可以使用以下命令

myTreeGrid().getStore().getRootNode().childNodes.length > 0

更正确的方法(因为理论上负载可能不会加载任何子节点)是在最初创建存储时将其连接到存储。在加载处理程序中,您可以在代码方便的地方设置
isLoaded
标志

差不多

var storeLoaded = false;
var store = Ext.create('Ext.data.TreeStore', {
    proxy: {
        type: 'ajax',
        url: 'get-nodes.php'
    },
    root: {text: 'Ext JS',id: 'src', expanded: true},
    listeners: {
       load: function() {
          storeLoaded = true;
       }
    }
 });

 var tree = Ext.create('Ext.tree.Panel', {
    store: store,
    renderTo: 'tree-div',
    height: 300,
    width: 250,
    title: 'Files'
 });