jstree onselect回调方法,获取选中节点的值 Fred


应用jstree的onselect事件,获取当前选中的节点的名字,并且赋值给一个input:
<script type="text/javascript">
function log(str) {
    $(
"#log").prepend(str + "<br />");
}
$(
function () {
    $(
"#demo").tree({
      data  : {
        type  : 
"json",
        json  : [ 
          { attributes: { id : 
"pjson4_1" }, data: "Root node 1", children : [
            { attributes: { id : 
"pjson4_2" }, data: { title : "Custom icon", icon : "../media/images/ok.png" } },
            { attributes: { id : 
"pjson4_3" }, data: "Child node 2" },
            { attributes: { id : 
"pjson4_4" }, data: "Some other child node" }
          ]}, 
          { attributes: { id : 
"pjson4_5" }, data: "Root node 2" } 
        ]
      },
      rules : {
        droppable : [ 
"tree-drop" ],
        multiple : 
true,
        deletable : 
"all",
        draggable : 
"all"
      },
      callback : {
                
onselect    : function (NODE) {    $("#txtSelectedValue").val($(NODE).children("a").text())} 

      }
    });
});
</script>
原文地址:https://www.cnblogs.com/Fred_Xu/p/jstree_onselect_callback.html