json - jsTree - 在 Json 数据中设置 href 属性

标签 json href jstree

我正在尝试创建一个“jsTree” TreeView ,它从 .Net Web 服务获取数据。 除了 a 节点的 href 属性之外,一切正常。无论我尝试什么,它总是呈现为“#”。 据我从文档中了解到,任何数据对象中的所有属性都会复制到 a 节点。

下面是我当前的 json 对象的示例。无论如何可以弄清楚为什么 href 属性没有复制到节点吗?

    [ { "attributes" : { "id" : "rootnode_2",
        "rel" : "root2"
      },
    "children" : [ { "attributes" : { "id" : "childnode_9",
              "rel" : "folder"
            },
          "children" : [ { "attributes" : { "id" : "childnode_23",
                    "rel" : "folder"
                  },
                "children" : null,
                "data" : { "href" : "http://www.google.com",
                    "title" : "Test_Below_1"
                  },
                "state" : null
              } ],
          "data" : { "href" : "http://www.google.com",
              "title" : "Test_1"
            },
          "state" : null
        },
        { "attributes" : { "id" : "childnode_10",
              "rel" : "folder"
            },
          "children" : [ { "attributes" : { "id" : "childnode_24",
                    "rel" : "folder"
                  },
                "children" : null,
                "data" : { "href" : "http://www.google.com",
                    "title" : "Test_Below_2"
                  },
                "state" : null
              } ],
          "data" : { "href" : "http://www.google.com",
              "title" : "Test_2"
            },
          "state" : null
        }
      ],
    "data" : { "href" : "http://www.google.com",
        "title" : "Glatt"
      },
    "state" : "closed"
  } ]

这就是我初始化树的方式;

$("#jstreejson").jstree({
        json_data : {
            "data": treeObject
        },
        themes: {
            "theme": "apple",
            "dots": true,
            "icons": true,
            "url": "/Scripts/themes/apple/style.css"
        },
        plugins: ['core', 'themes', 'json', "json_data"]
    });

最佳答案

所以...我不确定这是否完全正确。据我所知,您无法控制 anchor 属性,但您可以将内容添加到 json 中的 attr 哈希中,然后使用 select_node.jstree 事件打开所需的链接,即:

.bind("select_node.jstree", function (e,data) {
   var href_address = data.rslt.obj.attr("whatever");
   // open desired link
}

关于json - jsTree - 在 Json 数据中设置 href 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9513301/

相关文章:

php - 通过键名仅从 JSON 获取特定键/值,而不是全部

html - 如何在href标签中传递变量?

javascript - 在多个页面上平滑滚动导航

html - 从超链接中删除所有样式/格式

jquery - 在 jstree 节点文本和滚动条之间添加间隙

javascript - 从 php 制作的数组中提取数据并将其传递给 javascript twig

java - 如何更改Json格式?

Javascript 编码对 JSON 无效

jquery - 为不同节点类型配置jstree右键上下文菜单

javascript - 使用 Knockout 自定义绑定(bind)更新 JSTree