save state bootstrap-treeview

2019-08-20 08:20发布

问题:

I need to save the state with this component https://github.com/jonmiles/bootstrap-treeview So I have modify the source code here: https://github.com/jonmiles/bootstrap-treeview/blob/master/src/js/bootstrap-treeview.js

and I have added in the line 104 the code:

getNodes: $.proxy(this.getNodes, this),

and in the line 1209 the code:

Tree.prototype.getNodes= function (options) {
            console.log("--- getNodes ---");
           return this.nodes
     };

So when I execute the code :

var jsonData=x$(idTree).treeview('getNodes', { silent: true }); 

I have the JSON array. But when Use this JSON array in the

var objTree=$("idTree").treeview({
      data: jsonData,         // data is not optional
       color: "#428bca",
             expandIcon: 'glyphicon glyphicon-chevron-right',
              collapseIcon: 'glyphicon glyphicon-chevron-down',
              //nodeIcon: 'glyphicon glyphicon-bookmark',
              showTags: true,
              enableLinks:true
    });  

This generate problem in render tree in the outline...have you any suggestion?

回答1:

I have solve the problem:

my problem is the return value.. and this is correct way--> this.tree

Tree.prototype.getNodes= function (options) {
            console.log("--- getNodes ---");
           return this.tree
     };