English 中文(简体)
can jsTree use radio check
原标题:

i know there is a plugin for jsTree named jquery.tree.checkbox.js. that make the tree node multi checkable.

i just wondered if there is a plugin to raido check the tree node? or how can i modify jquery.tree.checkbox.js to achieve that?

最佳回答

This can simply be done by adding the attribute

    rules:{
            multiple : false
          } 

Inside the configuration of the tree. This will make it impossible to choose multiple entries.

问题回答

@Asaf s answer seems to no longer work on version 3.3.1 in 2016. You now need to set multiple on core:

$jstree.jstree({
    core: {
        multiple: false,
        ...
    }
});

Setting multiple:false will still allow cascading so you need to turn that off too.

version 3.3.3

$(".tree").jstree({
    plugins: ["checkbox"],
    core: {
        data: ...,
        multiple: false
    },
    checkbox: {
        three_state: false,
        cascade: "none"
    }
});

The radio button option is still not released, so you have to change the chceckbox option as single select.

bind( check_node.jstree , function(e, data) {
    var currentNode = data.rslt.obj.attr("id");
    $("#tree").jstree("get_checked",null,true).each 
        (function () { 
            if(currentNode != this.id){
                jQuery.jstree._reference($("#tree")).uncheck_node( # +this.id);
            }
        }); 
});

refer this http://jsfiddle.net/bwTrP/1/

Using jsTree version 3.2.1 with the checkbox plugin it is possible to emulate radiobutton behaviour handling the changed event as follows:

//jstree configuration:
 checkbox : {
    three_state: false, //required for the cascade none to work
    cascade:  none  //no auto all_children<->parent selection
},
//...

var resetting = false;
$( #tree ).on( changed.jstree , function (e, data) {
    if (resetting) //ignoring the changed event
    {
        resetting = false;
        return;
    }
    if ($("#multiselect").is( :checked ) == false && data.selected.length > 1) {
        resetting = true; //ignore next changed event
        data.instance.uncheck_all(); //will invoke the changed event once
        data.instance.check_node(data.node/*currently selected node*/);
    }
});

JSFiddle: JSTree radiobutton behaviour example using checkbox plugin





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签