javascript - how to build href in bootstrap-treeview? - Stack Overflow

I'm using bootstrap-treeview to display a tree-like view of my data. The initial and basic impleme

I'm using bootstrap-treeview to display a tree-like view of my data. The initial and basic implementation is working but I need it to when I click the text value, i get redirected to the link.

The JS function that renders the tree is:

function initTree(treeData) {
    $('#treeview_json').treeview({
        data: treeData,
        enableLinks: true
    });
    // collapses all nodes
    $('#treeview_json').treeview('collapseAll', { silent: true });
}

The enableLinks: true node property renders the link. But I could not find any documentation or example on the href property.

Does the link has to be supplied with the data or can it be built by the javascript?

I'm using bootstrap-treeview to display a tree-like view of my data. The initial and basic implementation is working but I need it to when I click the text value, i get redirected to the link.

The JS function that renders the tree is:

function initTree(treeData) {
    $('#treeview_json').treeview({
        data: treeData,
        enableLinks: true
    });
    // collapses all nodes
    $('#treeview_json').treeview('collapseAll', { silent: true });
}

The enableLinks: true node property renders the link. But I could not find any documentation or example on the href property.

Does the link has to be supplied with the data or can it be built by the javascript?

Share Improve this question asked Mar 5, 2018 at 10:54 gtludwiggtludwig 5,63113 gold badges69 silver badges96 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 4

You pass href as node attribute (see https://github./jonmiles/bootstrap-treeview#node-properties), so it is supplied with the data:

var tree = [
  {
    text: "Parent 1",
    nodes: [
      {
        text: "Child 1",
        nodes: [
          {
            text: "Google",
            href: "https://www.google."
          },
          {
            text: "Twitter",
            href: "https://www.twitter."
          }
        ]
      },
      {
        text: "Facebook",
        href: "https://www.facebook."
      }
    ]
  }
];

Check this example: https://jsfiddle/beaver71/bvpncxko/

Remember you must have enableLinks:true

function initTree(treeData) {
        $('#treeview_json').treeview({
            data: treeData,
            enableLinks: true,
        });
    }

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744874575a4598470.html

相关推荐

  • javascript - how to build href in bootstrap-treeview? - Stack Overflow

    I'm using bootstrap-treeview to display a tree-like view of my data. The initial and basic impleme

    1天前
    60

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信