jstree 选中、打开、解绑、清空

文章展示了如何通过$.ajax从服务器获取json数据,然后用这些数据初始化jstree,进行清空、解绑、重新绑定和节点操作。特别是,当有选定节点时,会自动打开并选择对应的父节点,并绑定了节点激活事件以触发特定函数。
摘要由CSDN通过智能技术生成

jstree 选中、打开、解绑、清空

           $.ajax({
                        type: "post",
                        dataType: "json",
                        url: "<?= url('bom/bomTree') ?>",
                        data: {'item_id': app.FItemID}
                    }).success(function (res) {
                        if (res.code > 0) {
                            let bom_tree_data = res.data;
                            let $bom_tree = $('#bom_tree');
                            $bom_tree.data('jstree', false).empty();//清空
                            $bom_tree.unbind();//解绑
                            $bom_tree.jstree({
                                'core': {
                                    "themes": {dots: true},
                                    "data": bom_tree_data
                                }
                            });
                            if (selected_node) {
                                let selected_parent = selected_node[0].parent;
                                $bom_tree.bind('ready.jstree', function (obj, e) {
                                    $bom_tree.jstree('select_node', selected_parent);
                                    $bom_tree.jstree('open_node', selected_parent);
                                })
                            }
                            //绑定
                            $bom_tree.bind("activate_node.jstree", function (obj, e) {
                                app.onBomInfo(e.node.id);
                            });
                        }
                    }).error(function () {
                        layer.msg("获取BOM信息失败");
                    });
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值