extjs6.0 treepanel设置展开和设置选中

var treePanel = {
                  id: "treeUrl",
                  xtype: "treepanel",
                  useArrows: true,                // 节点展开+,-图标全部改为小三角
                  expanded: true,                 // 默认展开
                  region: 'west',
                  width: "40%",
                  border: false,
                  bodyBorder: false,
                  autoScroll: true,
                  /** 资源树(数据集) */
                  store: {
                          storeId: 'Resources',       // 数据集ID
                          root: {                     // 根节点配置
                                  id: '1',                // 根节点ID
                                  expanded: true,         // 默认展开
                                  text: '资源文件目录'      // 根节点名称
                                },
                                proxy: {                    // 访问代理
                                         type: 'ajax',           // 类型异步
                                         api: {
                                                read: 'catalog/tree?type=fpd'
                                              }
                                       }
                                },
                                /** 监听器 */
                                listeners: {
                                    render: function () {
                                            if (JSON.stringify(movementChild.select) != "{}") {
                                                var _url = movementChild.select.localUrl.split("/");
                                                var childUrl = _url.pop()
                                                // 父节点id
                                                var parentUrl = _url.join("/")
                                                this.expandPath(parentUrl, 'id');
                                                var myThis = this;
                                                var num = 0;
                                                var time = setInterval(function () {
                                                    num++;
                                                    if (myThis.getSelectionModel().select(myThis.getStore().getNodeById(childUrl)) != undefined || num > 5) {
                                                        clearInterval(time)
                                                    } else {
                                                        myThis.getSelectionModel().select(myThis.getStore().getNodeById(childUrl))

                                                    }
                                                }, 100)
                                                me.treeAjax(movementChild,movementChild.select,"render")
                                            }
                                        },
                                        itemclick: function (_this, _record) {
                                            // 清空参数
                                            if (_record.data.leaf) {
                                                movementChild.select["localUrl"] = Ext.getCmp("leftresource").getController().getIdPath(_record);
                                                movementChild.select["serverPath"] = _record.data.node.path;
                                                movementChild.select["text"] = _record.data.text;
                                                //点击的时候根据路径查找参数
                                                me.treeAjax(movementChild,_record,"click")
                                            }
                                        },
                                   
                                        }
                                    },
                                },

treepanel 默认展开第一个节点

 this.getRootNode().firstChild.expand()
    原文作者:playboy5566
    原文地址: https://segmentfault.com/a/1190000015343131
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞