jsTree json href重定向

时间:2017-06-08 17:03:40

标签: json href jstree

所以,我使用jsTree并希望用href填充节点。但是当我点击节点时没有任何反应。

任何人都能看到我失踪的东西吗?

Html是:  div id =" container" /

脚本是:



    <script>
        $(function() {
            $('#container').jstree({!jsonString});
        });
    </script>
&#13;
    <div id="container">

    </div> 
&#13;
&#13;
&#13;

json数据是:

   {
  "core": {
    "data": [
      {
        "text": "Accounting",
        "state": {
          "opened": true
        },
        "children": [
          {
            "id": "a1u4D0000006KvkQAE",
            "a_attr": {
              "href": "www.google.com"
            },
            "text": "New Hire"
          },
          {
            "id": "a1u4D0000006KvpQAE",
            "a_attr": {
              "href": "www.google.com"
            },
            "text": "OnPay 2016 Docs"
          },
          {
            "id": "a1u4D0000006KvuQAE",
            "a_attr": {
              "href": "www.google.com"
            },
            "text": "Payroll Relief Docs"
          },
          {
            "id": "a1u4D0000006KvzQAE",
            "a_attr": {
              "href": "www.google.com"
            },
            "text": "Payroll Reports ",
            "children": [
              {
                "id": "a1u4D0000006Kw9QAE",
                "text": "2016 Reports",
                "children": [
                  {
                    "id": "a1u4D0000006KwTQAU",
                    "text": "2016a",
                    "children": [
                      {
                        "id": "a1u4D0000006LbsQAE",
                        "text": "2016a.1"
                      },
                      {
                        "id": "a1u4D0000006NErQAM",
                        "text": "2016a.2"
                      }
                    ]
                  },
                  {
                    "id": "a1u4D0000006KwYQAU",
                    "text": "2016b"
                  }
                ]
              },
              {
                "id": "a1u4D0000006KwEQAU",
                "text": "2017 Reports",
                "children": [
                  {
                    "id": "a1u4D0000006NMJQA2",
                    "text": "2017a"
                  },
                  {
                    "id": "a1u4D0000006NMOQA2",
                    "text": "2017b"
                  }
                ]
              }
            ]
          },
          {
            "id": "a1u4D0000006Kw4QAE",
            "a_attr": {
              "href": "www.google.com"
            },
            "text": "Setup"
          }
        ]
      }
    ]
  }
    }

1 个答案:

答案 0 :(得分:0)

您需要将每个节点的URL绑定到select_node事件,例如

$('#container').jstree({!jsonString})
    .bind("select_node.jstree", function (e, data) { document.location.href = data.node.a_attr.href; }));