代码之家  ›  专栏  ›  技术社区  ›  pithhelmet

JSTree绑定我自己的点击事件

  •  2
  • pithhelmet  · 技术社区  · 11 年前

    我正在使用jstree,并希望将我自己的点击事件绑定到每个节点。。。。

    这就是我正在尝试的。。。。

         $("#demo1").jstree({
       "core": { "initially_open": ["root"] },
       "html_data": {
         "data": out
       },
       "plugins": ["themes", "html_data"]
     }).bind("select_node.jstree", 
    function (e, data) 
    { 
      alert(data.rslt.obj.data("id"));     });
    

    我正在使用HTML_Plugin,将out变量设置为如下

    "<li id='root'><a href='#'>Root node</a><ul><li><a href='#'>Child node</a></li></ul></li>"
    

    问题是,点击事件似乎没有启动,因为我没有看到警报消息。

    请告诉我我的错误。

    谢谢 托尼

    2 回复  |  直到 11 年前
        1
  •  0
  •   Baby Groot Duleendra    11 年前

    从代码中删除以下属性并尝试,out变量会给您“out未定义的错误”

              "html_data": {
                 "data": out
               }, 
    
        2
  •  0
  •   pithhelmet    11 年前
       $("#demo1").jstree({
       "core": { "initially_open": ["root"] },
       "html_data": {
         "data": out
       },
       "plugins": ["themes", "html_data", "ui"]
     }).bind("select_node.jstree", function (e, data) {
       var id = data.rslt.obj.attr("id");
       var parent = data.inst._get_parent(data.rslt.obj);
       if (parent == -1) {
         alert(id);
       } else {
         alert(parent.find('a').first().text() + "|" + id);
       }
     });
    

    需要一件事。。。添加插件UI