質問

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 ?

役に立ちましたか?

解決

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

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top