【问题标题】:Selection of first node of a tree is not happening with xtype treecolumnxtype treecolumn 不会选择树的第一个节点
【发布时间】:2013-04-02 11:33:59
【问题描述】:

我通过将 xtype 指定为 treecolumn 创建了一个树面板。我想选择树的第一片叶子。在这个例子中,我注册了 boxready 事件,详情如下:

boxready : function( treePanel, width, height, eOpts ){

    treePanel.getSelectionModel().select( 0 );
    //treePanel.select( treePanel.getRootNode().getChildAt(0) );
    treePanel.getSelectionModel().selected = 0;
},
treePanel.getSelectionModel()

这个例子给了我 SINGLE 类型的 selectionmodel。谁能解释为什么我的示例没有选择第一片叶子?

【问题讨论】:

    标签: ext4


    【解决方案1】:

    这是一个小“图”:

    如果你需要从头开始的叶子:

    • 已选择一个节点:

      var nodeData = treePanel.getSelectionModel().getSelection();

    • 从头开始:

      var node = treePanel.getRootNode(); -- 父亲(第一个节点);

      findLeaf : 函数(节点){

      if(node.isLeaf()){
      // this is the node that u want
      }else{
          // bucle to find it
          node.eachChild(function(nodeChild,array){
              if(nodeChild.isLeaf()){
                 // this is the node that u want
              }else{
                 // get childs of this node
                 if(nodeChild.hasChildNodes()){
                      //find the childs from this node.
                      this.findLeaf(nodeChild);
                 }
              }
          });
      }
      

      };

    【讨论】:

    • 在我的情况下没有选择节点,所以我通过 var node = treePanel.getRootNode();但在组件内部,我得到了 0 个项目的 childNodes,因此它不会进入 foreach 循环。你能告诉我哪里不见了吗?
    • 如果你没有选择一个,你需要得到根节点。也许,你可以从树店得到它。但我认为你的存储是空的,错误...
    • 是的,你是对的。当时店里空无一人。所以我将代码移动到 store.onload,现在它工作正常。
    猜你喜欢
    • 2015-06-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多