how to use the types plugin in the JsTree with json

4,742 views
Skip to first unread message

伟叶

unread,
Feb 8, 2014, 3:03:10 AM2/8/14
to jst...@googlegroups.com
the JsTree version is 3.0.0-beta 5

I define the two types and use the types plugin

                "plugins" : ["themes", "json_data", "ui","types"],

             "tyes":{
            "default":{
            "icon" : "glyphicon glyphicon-flash"
            },
            "demo":{
            "icon" : "glyphicon glyphicon-ok"
            }
            },

then in the java side i return the json data with following format

[{"id":"2","text":"skill","li_attr":{"rel":"demo"},"children":false},{...}]

but the icon of nodes does not display, it just display the default icon.


Note: yes, I can use the icon parameter in json to pass the url of icon to front end, and it works.

But i want to know how can i display icons based on the types by using the types plugin




Tom Beech

unread,
Feb 8, 2014, 5:34:27 PM2/8/14
to jst...@googlegroups.com
Your json needs to be slightly different:

[{"id":"2","text":"skill","type":"demo","children":false},{...}]

torsion

unread,
Feb 9, 2014, 10:27:25 PM2/9/14
to jst...@googlegroups.com
First it looks like you have a spelling mistake there. It's "types" (not "tyes").
Secondly instead of using "rel" : "demo" try using "type" : "demo".
Thirdly check the version of bootstrap you are using. The newer one calls their icons a  bit differently (i.e. "icon" : "icon icon-ok-sign")
And finally (if #3 does not work) try to declare your icon in json: [{"id":"2","text":"skill","icon":"icon icon-ok-sign","li_attr":{"rel":"demo"},"children":false},{...}]
Hope it will help.

伟叶

unread,
Feb 9, 2014, 11:53:45 PM2/9/14
to jst...@googlegroups.com
Thank you very much

I miss-spell the "types" ( sorry for my carelessness)

and i should use the "type"  rather than "li_attr"

currently, it works now


在 2014年2月10日星期一UTC+8上午11时27分25秒,torsion写道:

Андрей Гладенко

unread,
Jul 23, 2020, 5:45:49 AM7/23/20
to jsTree
Hello, I have same question, but how should I perform it when
instead of { type: "..." } in my json data Server returns { entity: "..." }
Reply all
Reply to author
Forward
0 new messages