SharpCoder
SharpCoder

Reputation: 19183

Bootstrap treeview expand collapse icon coming for leaf nodes

I am using bootstrap treeview. For some reason, even the leaf nodes are having expand/collapse icons. I want to show expand/collapse icons only for non-leaf nodes?

I am using following config:

  $('#tree').treeview({data: scope.tree, showCheckbox: true});
  $('#tree').treeview('collapseAll', { silent: true });

I am sure there must be a configuration to enable disable expand/collapse icons for leaf nodes in treeview.

Upvotes: 3

Views: 3741

Answers (1)

SharpCoder
SharpCoder

Reputation: 19183

To answer my own question, In the JSON, the nodes property needs to be set as null for leaf nodes. I was sending it as empty array []

var tree = [
  {
    text: "Parent 1",
    nodes: [
      {
        text: "Child 1",
        nodes: [
          {
            text: "Grandchild 1"
          },
          {
            text: "Grandchild 2"
          }
        ]
      },
      {
        text: "Child 2"
      }
    ]
  },

  {
    text: "Parent 4"
    nodes: []  // =======> set this as null
  }
];

Upvotes: 5

Related Questions