Vimal
Vimal

Reputation: 404

Add clickable button on each node in jstree in jsp

I have list of value in object. I need to add button on each node in jstree.

My code :

This is static code which is working for single value.

$('#tree').jstree({
core:{
    data:[
        '<button>Press</button> One'
    ]
},
plugins:['checkbox']

});

but i want to add button dynamically to each node.

var arrayCollections = ${jsonArray};
$('#jstreesD').jstree({
    'core' : {

            ],
        'data' :[ arrayCollections,'<button>Press</button> Ok'],

    },
})

 <div id="jstreesD"></div>

but this is not working. Is there a way to do like this.

Thanks, VJM

Upvotes: 0

Views: 4894

Answers (1)

Leguest
Leguest

Reputation: 2137

I think you could try this:

    $(function () {

        var data =  [ { "id" : "100", "parent" : "#", "text" : "MyData" }, { "id" : "155", "parent" : "MyData", "text" : "Test", } ]

        $('#jstree').jstree({
            'core' : {
                'data' : data.map(function(item){

                    return "<button>Press</button>" + item.text
                })

            }
        });
    });

JSFiddle Example

Upvotes: 1

Related Questions