Select 默认情况下树面板中的节点

Select node in treepanel by default

我正在使用 extjs 3.4

我希望在首次加载树面板时预选节点。在我的示例中,这将是第二个节点。与鼠标单击该节点相同 - 默认情况下它发生在选定节点上。 那么,如何模拟鼠标点击第二个节点呢? (或者默认设为活动项)

Ext.ns('App.Misc.West');

App.Misc.West.View = Ext.extend(Ext.Panel, {
    constructor: function (config) {
        var me = this;
        var cfg = {
            items: [{
                xtype: 'treepanel',
                ref: 'treeMisc',
                id: 'treeMisc',
                root: new Ext.tree.AsyncTreeNode({
                    expanded: true,
                    text: 'Data tables',
                    children: [{
                        text: 'Books',
                        bookTitle: 'Books',
                        leaf: true
                    }, {
                        text: 'Cars',
                        bookTitle: 'Cars',
                        leaf: true
                    }]
                }),
                rootVisible: true
            }]
        };
        Ext.apply(cfg, config);
        App.Misc.West.View.superclass.constructor.call(me, cfg);
    }
});

您可以在 'load' 和节点 'expand' 处理程序中以编程方式使用选中(多个 selection 和复选框)或 select:

new Ext.tree.TreePanel({
    region: 'west',
    collapsible: true,
    title: 'Navigation',
    xtype: 'treepanel',
    width: 200,
    autoScroll: true,
    split: true,
    loader: new Ext.tree.TreeLoader({
        listeners: {

        }
    }),
    root: new Ext.tree.AsyncTreeNode({
        expanded: true,
        text: 'Data tables',
        children: [{
            text: 'Books',
            bookTitle: 'Books',
            leaf: true
        }, {
            text: 'Cars',
            bookTitle: 'Cars',
            leaf: true,
            //checked: true // <-- selected with checkbox
        }]
    }),
    rootVisible: false,
    listeners: {
        // Single selection (simulated mouse click)
        load: function (treeLoader, node) {
            this.getRootNode().on('expand', function (node) {
                this.getSelectionModel().select(this.getRootNode().childNodes[1]);
            }, this);
        }
    },
    renderTo: Ext.getBody()
});