Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/86.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery .使用jsTree加载_Jquery_Jquery Plugins_Jstree - Fatal编程技术网

Jquery .使用jsTree加载

Jquery .使用jsTree加载,jquery,jquery-plugins,jstree,Jquery,Jquery Plugins,Jstree,我正在帮助一个朋友建立jsTree。我们正试图做到这一点,当一个节点被点击时,一个页面被加载到另一个div中。然而,一切似乎都在运行,但由于某种原因,.load无法启动。我使用alert检查此项,它已定义并且是正确的变量 $(function() { $('.tree').jstree().delegate("a", "click", function(event, data){ event.preventDefault(); var thisItem

我正在帮助一个朋友建立jsTree。我们正试图做到这一点,当一个节点被点击时,一个页面被加载到另一个div中。然而,一切似乎都在运行,但由于某种原因,
.load
无法启动。我使用alert检查此项,它已定义并且是正确的变量

$(function() {

    $('.tree').jstree().delegate("a", "click", function(event, data){
        event.preventDefault();
        var thisItem = $(this).attr('id');
        thisItem += ".html";
        alert(thisItem);
        $('.table').load(thisItem);
        });

});
这是HTML:

<div class = "tree">  
    <ul>
    <li id = "1"><a href = "" id = "1">Test 1</a>
        <ul>
        <li id = "2"><a href = "" id = "2">Test 2</a></li>
        </ul>
    </li>
    </ul>
</div>
<div class = "table">
</div>

注意:这只是对项目中更具活力部分的测试。

请查看此处的第一个演示:

你的点击处理程序不工作,因为我相信插件本身会解除点击处理程序的绑定,因为它们使用自己的自定义事件。您可以通过与第一个演示中相同的方法绑定到这些事件中

$("#demo1").jstree("toggle_node","#phtml_1");
$("#demo1").bind("open_node.jstree close_node.jstree", function (e) {
    //Stuff
});

这些事件似乎遵循“function.jstree”的形式。因此,
open\u node.jstree
事件是在
open\u node
函数发生后触发的。您可以在上面的同一链接上找到函数列表。

您可以通过将自定义事件(
some event.jstree
)绑定到jstree元素来执行自己的代码,在本例中,您要查找的是
select_node.jstree

$('.tree').bind("select_node.jstree", function (e, data) {
   var $obj = data.rslt.obj; // this will be a jquery object representing the <li> you've clicked
   var url = $obj.attr("id") + ".html";
   $('.table').load(url);
});
希望这有帮助

$('.tree').bind("select_node.jstree", function (e, data) {
   var $obj = data.rslt.obj; // this will be a jquery object representing the <li> you've clicked
   var url = $obj.attr("id") + ".html";
   $('.table').load(url);
});
{
   "inst" : /* the actual tree instance */,
   "args" : /* arguments passed to the function */,
   "rslt" : /* any data the function passed to the event */,
   "rlbk" : /* an optional rollback object - it is not always present */
}