javascript - ExtJS:如何动态地将子节点添加到树面板

标签 javascript extjs openlayers

如何使用 JavaScript 以编程方式向现有 TreePanel 添加子节点?

我有一个显示 map 事件图层的 TreePanel(使用 GeoExt):

treeConfig = new OpenLayers.Format.JSON().write([{
    nodeType: "gx_baselayercontainer",
    text: "Base layers",
    expanded: true
    }, {
    nodeType: "gx_overlaylayercontainer",
    text: "Overlays",
    expanded: true,
    loader: {
        baseAttrs: {
            radioGroup: "foo",
            uiProvider: "use_radio"
        }
    }
}], true);

treePanel = new Ext.tree.TreePanel({
    id: 'mainpanel',
    border: true,
    region: "west",
    title: "Map layers",
    width: 200,
    split: true,
    collapsible: true,
    margins: '0 0 5 5',
    collapseMode: "mini",
    autoScroll: true,
    loader: new Ext.tree.TreeLoader({
        applyLoader: false,
        uiProviders: {
            "use_radio": LayerNodeUI
        }
    }),
    root: {
        nodeType: "async",
        children: Ext.decode(treeConfig)
    },
    listeners: {
        "radiochange": function(node){
            alert(node.layer.name + " is now the the active layer.");
        }
    },
    rootVisible: false,
    lines: false
});

用户应该能够通过按下按钮来添加覆盖层,但是我似乎找不到任何关于如何完成此操作的示例。

有什么想法吗?

最佳答案

通过getNodeById抓取父节点或 getRootNode并添加带有 appendChild 的子节点.

关于javascript - ExtJS:如何动态地将子节点添加到树面板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3194419/

相关文章:

javascript - 使用 phantomjs 在本地文件上使用 extjs 代理进行 ajax 调用

javascript - ExtJs 3.4 : Move selected items from one grid to another on a button click

javascript - 将选定的记录加载到模态窗口

openlayers - 如何让 OpenLayers Vector Layer 始终绘制所有特征,而不管缩放、范围等如何?

javascript - 如果只选中一个复选框,如何向前跳过一步并设置一个值

javascript - Kendo ui - 在 child 添加/编辑时获取父网格项目(网格层次结构)

javascript - Jquery 正确隐藏 iframe,但点击时不显示它

javascript - 如何检测网页是否发生变化?

css - 通过 CSS 设计 SOS 点功能

javascript - 概览图始终显示整个 map