can we go one level up node using jquery?

无人久伴 提交于 2019-12-11 11:05:23

问题


I make a demo of tree view using jstree .I am able to move next and previous element selectable. Ecample Click "b" now it is selectable and then press next and previous it it move active class. Can we go one level up using "one level up button" when user selects "b-a" and when user clicks next it comes to "b-b" and previous it come to "b-a".

It never goes one level up can we go one level up using "one level up button" then it goes to "b" http://jsfiddle.net/fuu94/60/

$('#next').click(function () {
    if($('.jstree-clicked').closest('li').next().length)
        $('.jstree-clicked').removeClass('jstree-clicked').closest('li').next().find('a:eq(0)').addClass('jstree-clicked')

});
 $('#pre').click(function () {
     if($('.jstree-clicked').closest('li').prev().length)
        $('.jstree-clicked').removeClass('jstree-clicked').closest('li').prev().find('a:eq(0)').addClass('jstree-clicked')

});

    $('#onelvel').click(function () {
    alert('one level up')
});

if user is at "b" and press "above level" it should behave like prevoius ? may i right ?


回答1:


Try this,

$('#onelvel').click(function () {
    if($('.jstree-clicked').length){
        $('.jstree-clicked').click();
        if($('.jstree-clicked').closest('.jstree-children').prev('.jstree-anchor').length){
            $('.jstree-clicked').removeClass('.jstree-clicked');
            $('.jstree-clicked').closest('.jstree-children').prev('.jstree-anchor').addClass('.jstree-clicked');
        }
    }
});

Live Demo

Updated try this,

$('#onelvel').click(function () {
    if($('.jstree-clicked').length){
        if($('.jstree-clicked').next('.jstree-children').length){
            $('.jstree-clicked').click();
        } else {
            $('.jstree-clicked').closest('.jstree-children').prev('.jstree-anchor').click().addClass('jstree-clicked');
        }         
    }
});

Updated demo



来源:https://stackoverflow.com/questions/23483103/can-we-go-one-level-up-node-using-jquery

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!