【问题标题】:JsTree one node with two parentJsTree 一个节点有两个父节点
【发布时间】:2018-10-22 15:27:35
【问题描述】:

我在 ui 中显示 jstree 并用 asp.net 服务器端代码中的 json 填充它,它工作得很好,但是当我有一个节点和两个父节点时,它不能很好地工作。 我可以显示一个节点和两个父节点的 jstree 吗? 当我这样做时,它会显示错误。 两个父母之间的孩子! 我知道它不是树角色,但我需要它。

    $(function () {

        $('#jstree').jstree({
            'core': {
                "animation": 0,
                "check_callback": true,
                "themes": { "stripes": true },
                'data': {
                    'url': '/Products/ProductCategoryStructure/GetData',
                    'data': function (node) {
                        return { 'id': node.id };
                    }
                }
            },
            "types": {
                "#": {
                    "max_children": 1,
                    "max_depth": 4,
                    "valid_children": ["root"]
                },
                "default": {
                    "valid_children": ["default", "file"]
                },
                "file": {
                    "icon": "glyphicon glyphicon-file",
                    "valid_children": []
                }
            },
             plugins: ["contextmenu"], contextmenu: {items: customMenu}
        });


        $('#jstree').on('changed.jstree', function (e, data) {
            var i, j, r = [];
            for (i = 0, j = data.selected.length; i < j; i++) {
                r.push(data.instance.get_node(data.selected[i]).text);
            }
            //alert('Selected: ' + r.join(', '));
            // $('#event_result').html('Selected: ' + r.join(', '));
        }).jstree();
    });

这是服务器端代码

        [HttpGet]
        public ActionResult GetData()
        {
            var ListProductCategoryStructure = _service.GetAll();
            var nodes = new List<JsTreeModel>();
            //nodes.Add(new JsTreeModel() { id = "58", parent = "#", text = " مادیران مال",opened=true,icon="/assets/pages/img/mlgo.png" });
            nodes.Add(new JsTreeModel() { id = "1", parent = "#", text = " مادیران مال", opened = true, icon = "/assets/pages/img/mlgo.png" });
            foreach (var item in ListProductCategoryStructure)
            {
                nodes.Add(new JsTreeModel() { id = item.ProductCategoryId.ToString(), parent = (item.ProductParentCategoryId==65?"#": item.ProductParentCategoryId.ToString()), text = item.ProductParentCategoryTitle,icon="false" });
            }
            
            return Json(nodes, JsonRequestBehavior.AllowGet);
        }
这是结果

【问题讨论】:

    标签: html asp.net json tree jstree


    【解决方案1】:

    一个节点只能有一个父节点。

    【讨论】:

    • 我做到了。谢谢我更改了我的数据库表并设置了 uniq 值并在树视图中选择它作为父项
    • 我从一开始就不明白。你能用图片告诉我你是做什么的吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-01
    • 2021-08-13
    • 1970-01-01
    相关资源
    最近更新 更多