关于jstree的一些应用记录

			<input id="optunitid" type="hidden"/>
            <input class="form-control input-medium" type="text" id="optunitname" placeholder="所属运营单位" readonly>
            <div class="select-treebox selectbox-medium" style="height: 550px;overflow: auto;position: absolute; z-index: 10">
                <div id="tree_optunit" class="tree-demo" style="width:12%;float:left;margin-top:2.8%;"></div>
            </div>

js:
			$(function () {
        var selectBox = $(".select-treebox");
        $("#optunitname").click(function (event) {
            $(this).parent().find(selectBox).toggle();
            $(document).one("click",
                function () {
                    $(selectBox).hide();
                });
            event.stopPropagation();
        });
        $(selectBox).click(function (event) {
            event.stopPropagation();
        });
    });
			
	$("#tree_optunit").jstree({
        "core": {
            "themes": {
                "responsive": false
            },
            // so that create works
            "check_callback": true,
            'data': {
                'url': function (node) {
                    return '${contextPath}/Group/showOptunitTree';
                },
                'dataType': 'json',
                'data': function (node) {
                    return {'parent': node.id};
                }
            }
        },
        "types": {
            "default": {
                "icon": "fa fa-folder icon-state-warning icon-lg"
            },
            "file": {
                "icon": "fa fa-file icon-state-warning icon-lg"
            }
        },
        "state": {"key": "demo3"},
        "plugins": ["html_data", "types"]
    }).on("changed.jstree", function (e, data) {
        if (data.node != undefined) {
            $('#optunitname').val(data.node.text);
            $('#optunitid').val(data.node.id);
            $('.select-treebox').hide();
        }
    });


Service:

@Override
    public Object showOptunitTree() {
        List<OptunitInfo> optunitList =optunitDao.listAllOptunit();
        JsTreeJson optunitTree;//城市树

        List<JsTreeJson> optunitTreeList = new ArrayList<>();

        if (optunitList != null && optunitList.size() > 0) {
            optunitTreeList = new ArrayList<>();
            for(TOptunit optunit : optunitList){
                optunitTree = new JsTreeJson(optunit.getOptunitid().toString(), optunit.getOptunit_name(), null, null, null);
                optunitTreeList.add(optunitTree);
            }
        }
        return optunitTreeList;
    }

mapper:
<select id="listAllOptunit" resultType="com.sunland.dto.OptunitInfo">
        select * from t_optunit
    </select>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值