【发布时间】:2017-12-23 11:35:04
【问题描述】:
这是我的 html(在树枝模板中)
<li id="{{folder.id}}" data-jstree='{"icon":"glyphicon glyphicon-tags", "type":"folder"}' ><a href="#">{{folder.name}}</a>
我正在尝试从 'data-jstree' 中获取 'type' 的值。
我尝试过使用
var node_id = ref.get_node(sel[i]).id;
var type = $("#"+node_id).attr("data-jstree");
但这给了我这个:{"icon":"glyphicon glyphicon-tag", "type":"tag"} 我只需要类型的值。
提前致谢。
【问题讨论】:
-
$("#"+node_id).data("jstree").type
-
var type = JSON.parse($("#"+node_id).attr("data-jstree")).type;
标签: javascript jquery html attributes