2012-08-28 75 views
1

我正在使用jstree_pre1.0_fix_1。我想要预先选择菜单。jstree最初选定的菜单导致无限循环;

JavaScript是以下,

$("#Menu").jstree({ 
    "plugins" : [ "themes", "html_data", "ui"], 
    "ui" :{ "initially_select" : ["#MENUITEM_012"] }, 
    "themes" : { 
     "theme" : "custom", 
     "dots" : false, 
     "icons" : false, 
    }, 
}). 
bind("select_node.jstree", function(e,data) { 
    window.location.href = data.rslt.obj.children("a").attr("href"); 
}); 

当jstree被加载时,它选择一个节点(#MENUITEM_012),然后window.location.href被改变,然后jstree加载并再次选择的节点。

我怎样才能摆脱这种情况。

+0

这条线的要点是什么? window.location.href = data.rslt.obj.children(“a”)。attr(“href”); –

+0

每个节点都有'a'标签。例如,'

  • TITLE012
  • '。所以当节点被选中时,新的页面被加载。 – Nishimu

    +0

    你试过我的解决方案吗? –

    回答

    0

    回答我自己;

    删除

    .bind("select_node.jstree", function(e,data) { 
        window.location.href = data.rslt.obj.children("a").attr("href"); 
    }) 
    

    添加

    $(".jstree li a").live("click", function(e) { 
        window.location.href = $(this).attr("href"); 
    }); 
    
    +0

    您是否找到比此更好的解决方案? –

    0

    就找到了解决办法。该问题是由试图选择节点的库引起的(即,使其在导航页面加载后显示为选中状态)。当访问节点将页面导航到另一个页面时,处理程序已设置。

    解决方案是确保节点通过单击鼠标进行选择。

    .bind("select_node.jstree", function(e,data) { 
        var evt = window.event || event; 
        var button = evt.which || evt.button; 
        if(button != 1 || (typeof button == "undefined")) return true; 
    
        window.location.href = data.rslt.obj.children("a").attr("href"); 
    })