zoukankan      html  css  js  c++  java
  • zTree默认选中指定节点并执行事件

    var treeObj = $.fn.zTree.getZTreeObj("treeDemo");
    var node = treeObj.getNodeByParam("id", "370000");
    treeObj.selectNode(node);
    setting.callback.onClick = onClick;
    
    //要执行的方法
    function onClick() {......}



    方法二:
    var zTree;
        var demoIframe;
    
        var setting = {
            view: {
                dblClickExpand: false,
                showLine: true,
                selectedMulti: false
            },
            data: {
                simpleData: {
                    enable:true,
                    idKey: "id",
                    pIdKey: "pId",
                    rootPId: ""
                }
            },
            callback: {
                beforeClick: function(treeId, treeNode) {
                    var zTree = $.fn.zTree.getZTreeObj("tree");
                    if (treeNode.isParent) {
                        zTree.expandNode(treeNode);
                        return false;
                    } else {
                        demoIframe.attr("src",treeNode.file + ".html");
                        return true;
                    }
                }
            }
        };
    
    var zNodes = [
            {id:1, pId:0, name:"[core] Basic Functions", open:false},
            {id:101, pId:1, name:"Standard JSON Data", file:"core/standardData"},
            {id:102, pId:1, name:"Simple JSON Data", file:"core/simpleData"}];
    
        $(document).ready(function(){
            var t = $("#tree");
            t = $.fn.zTree.init(t, setting, zNodes);
            demoIframe = $("#testIframe");
            demoIframe.bind("load", loadReady);
            var zTree = $.fn.zTree.getZTreeObj("tree");
    
    //下面这段可以放在其他地方,比如配合搜索功能使用,搜索到节点ID然后触发点击事件
            var treeNode=zTree.getNodeByParam("id", 301)
            zTree.selectNode(treeNode);
            if (treeNode.isParent) {
                zTree.expandNode(treeNode);
                 
            } else {
                demoIframe.attr("src",treeNode.file + ".html");
                 
            }
        
        });
    
    
    <TABLE border=0 height=600px align=left>
        <TR>
            <TD width=260px align=left valign=top style="BORDER-RIGHT: #999999 1px dashed">
                <ul id="tree" class="ztree" style="260px; overflow:auto;"></ul>
            </TD>
            <TD width=770px align=left valign=top><IFRAME ID="testIframe" Name="testIframe" FRAMEBORDER=0 SCROLLING=AUTO width=100%  height=600px SRC="core/standardData.html"></IFRAME></TD>
        </TR>
    </TABLE>
  • 相关阅读:
    webpack的入门实践,看这篇就够了
    vue系列教程-15vuex的使用
    vue系列教程-14axios的使用
    vue系列教程-13vuecli初体验
    vue系列教程-12vue单文件组件开发
    vue系列教程-11vuerouter路由
    vue系列教程-10vue过滤器和自定义指令
    vue系列教程-09vue组件
    Spring Redis开启事务支持错误用法导致服务不可用
    MySQL主从数据库配置与原理
  • 原文地址:https://www.cnblogs.com/skyislimit/p/5817275.html
Copyright © 2011-2022 走看看