Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get the text of the currently selected node in jstree?

This seems like it should be simple to do, but the jstree "data.rslt.obj.text()" method likes to return the text of the current node as well as all of its children. I've figured out how to get the current node name with renaming a node (new_name), but how do I get the text of ONLY the current node when I simply select it? Also, I'd appreciate any insight into how I would find all of these methods and properties in the jstree using chrome or firebug. Where would I look in the list of elements that come up when I select "data.rslt", for instance. Thanks!

 $("#RequirementsTree")
    .bind("select_node.jstree", function(event, data) {
            if(is_requirement_node(data))
            {
                var ReqCheck = data.rslt.obj.attr("name");

                @* This is a REQUIREMENT *@
                if(ReqCheck == "requirement")
                {
                    $("#RMSDoc_RequirementFlag").val("EDIT");
                    $("#RMSDoc_RBSRequirement_RequirementsId").val(data.rslt.obj.attr("id").substring(4));
                    $("#RMSDoc.RBSRequirement.RequirementsId").val(data.rslt.obj.attr("id").substring(4));
                    $("#RMSDoc_RBSRequirement_RequirementsText").val($.trim(data.rslt.obj.text()));
                    $("#RMSDoc_TreeBranch_Text").val("");
                    $("#HierarchyText").hide();
                    $("#RMSDoc_TreeBranch_Text").hide();
                    $("#ExistingTreeSubmit").val("@Model.RMSDoc.RMSEditReqButton.ConfigurableLabelDesc");

                }
                else {
                    alert("Requirement node select error");
                }
            }
            @* This is a TREE BRANCH *@
            else
            {
                debugger;
                $("#RMSDoc_RequirementFlag").val("ADD");
                $("#HierarchyText").show();
                $("#RMSDoc_TreeBranch_Text").show();
                $("#RMSDoc_TreeBranch_Text").val($.trim(data.rslt.obj.text()));
                $("#RMSDoc_TreeBranch_id").val(data.rslt.obj.attr("id").substring(4));
                $("#RMSDoc_RBSRequirement_RequirementsText").val("");
                $("#ExistingTreeSubmit").val("@Model.RMSDoc.RMSCreateReqButton.ConfigurableLabelDesc");
            }
     })
    .bind("create.jstree", function(e, data) {
like image 689
TheDude Avatar asked Sep 07 '12 15:09

TheDude


1 Answers

If you are using the jstree with the checkboxes on you can check for the length of the checkbox selectors.

if ($('.jstree-checked').length == 1) {
    alert( 'Checked Item -: ' + $('.jstree-checked').text() );
}

If you are not into checkboxes then use this selector.

if ($('.jstree-clicked').length == 1) {
    alert( 'Selected Item -: ' + $('.jstree-clicked').text() );
}

To get the list of all the items and methods for the jstree , you need to put a debug point in either chrome or Firebug in the jstree.js file .. For example you can find the .bind method in the .js and put a debug point on that particular line.. When that point hits you can hover over the arguments to get a glimpse of the methods in it..

like image 64
Sushanth -- Avatar answered Oct 05 '22 18:10

Sushanth --