Avatar of Evan Cutler
Evan Cutler
Flag for United States of America asked on

JSTREE Check failure

Greetings...
I'm trying to fire this line:
$("#DivTree").jstree("check_node", $(this).text());

The $(this).text() works (I checked in firebug)...
but the Tree does not check the node...
help?

Here's the code to the entire page:
 
<%@ Page Title="" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="Scratchpad.aspx.cs" Inherits="Scratchpad_Scratchpad" %>



<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" Runat="Server">
    <%--CSS links--%>
    <link href="../Styles/ui-lightness/jquery-ui-1.8.14.custom.css" rel="stylesheet" type="text/css" />
    <link href="../Styles/grid/flexigrid.css" rel="stylesheet" type="text/css" />
    <link href="../Styles/textarea/jquery.cleditor.css" rel="stylesheet" type="text/css" />

    <%--Javascript links--%>
    <script src="../Scripts/jquery-1.6.2.min.js" type="text/javascript"></script>
    <script src="../Scripts/jstree/jquery.jstree.js" type="text/javascript"></script>
    <script src="../Scripts/ui/jquery-ui-1.8.14.custom.js" type="text/javascript"></script>
    <script src="../Scripts/Grid/flexigrid.js" type="text/javascript"></script>
    <script src="../Scripts/textarea/jquery.cleditor.js" type="text/javascript"></script>
    <script type='text/javascript' language='javascript'>

        $(document).ready(function () {


            $("#update").button();
            $("#update").hide();
            $("#addnew").button();
            $("#Text").cleditor();
            $("#divTree").jstree({
                "xml_data": {
                    "ajax": {
                        "url": "../data_services/Menu.ashx",
                        //"url": "FieldsOfStudyAdmin.aspx?callback=GetNodesJson",
                        "data": function (n) {
                            return { id: n.attr ? n.attr("id") : 0 };
                        }
                    }
                },
                "checkbox": {
                    "two_state": true,
                    "override_ui": true
                },
                "plugins": ["themes", "xml_data", "search", "dnd", "ui", "checkbox"]
            }).bind("check_node.jstree uncheck_node.jstree", function (e, data) {
                var checked_ids = new Array();
                $.jstree._focused().get_checked(-1, true).each(function () {
                    if (this.id) { checked_ids.push(this.id); }
                });
                $("#Fields").val(checked_ids.join(", "));
            });



            $("#ads").flexigrid({
                url: '../data_services/Ads.ashx',
                dataType: 'xml',
                method: 'GET',
                colModel: [
		            { display: 'Title', name: 'Title', width: 150, sortable: true, align: 'left', process: getID },
		            { display: 'Text', name: 'Text', width: 250, sortable: true, align: 'left', process: getID },
		            { display: 'Date', name: 'Date', width: 150, sortable: true, align: 'left', process: getID },
		            { display: 'Fields', name: 'Fields', width: 200, sortable: true, align: 'left', process: getID }
		        ],
                searchitems: [
		            { display: 'Title', name: 'Title' },
		            { display: 'Text', name: 'Text', isdefault: true }
		        ],
                sortname: "Title",
                sortorder: "asc",
                usepager: true,
                title: 'Countries',
                singleSelect: true,
                useRp: true,
                rp: 15,
                showTableToggleBtn: true,
                width: 750,
                height: 200
            });
            $('#update').click(function () {
                var text = $('#Text').val();
                text = text.replace("\n", "");
                text = text.replace("\r", "");
                alert(text);
            });
            function getID(celDiv, id) {
                $(celDiv).click(function () {
                    $("#pk").val(id);
                    $.ajax({
                        type: "Post",
                        url: "../data_services/AdForm.asmx/GetAd",
                        dataType: "xml",
                        data: "PK=" + id,
                        success: function (xml) {
                            $(xml).find('formdata').each(function () {
                                var fieldlist = new Array();
                                $("#Title").val($(this).find('title').text());
                                $("#Text").val($(this).find('text').text());
                                $("#Text").cleditor()[0].updateFrame();
                                $(this).find('fields').each(function () {
                                    $(this).find('field').each(function () {
                                        fieldlist.push($(this).text());
                                        $("#DivTree").jstree("check_node", $(this).text());
                                    });
                                });
                                $("#Fields").val(fieldlist.join(', '));
                                $("#update").show();


                            });
                        }
                    });
                });
            };
            $("#search").click(function () {
                $("#divTree").jstree("search", $("#fieldsearch").attr('value'));
            });
        });
    </script>
</asp:Content>
<asp:Content ID="Content2" runat="server" contentplaceholderid="MainContent">
<table id="ads"></table>
<div id="output"></div>

<div id="form">
<table>
    <tr>
        <td>
        PK:     <input id="pk" /><br />
        Title:  <input id="Title" value="insert Title Here" size="71" /><br />
        Fields: <input id="Fields" size="70"/><br />
        Text:   <textarea id="Text" rows="10" cols="80"></textarea>
        </td>
        <td>
            <input id="fieldsearch" type="text" /><div id="search"><a href="#">search for node</a></div><br />
            <div id="divTree"></div>
        </td>
    </tr>
</table>
<a href="#" id="update" >Update Advertisement</a><a href="#" id="addnew">Add new Advertisement</a>
</div>
</asp:Content>

Open in new window


help?
JavaScriptHTMLASP.NET

Avatar of undefined
Last Comment
leakim971

8/22/2022 - Mon
leakim971

>The $(this).text() works (I checked in firebug)...

what $(this).text() return ? the id of the checkbox? the class of the checkbox? or the text?

if this is the text, try this instead :
$("#DivTree").jstree("check_node", "li:contains('" + $(this).text() + "')");

Open in new window

Evan Cutler

ASKER
http://cutlerplace.net/data_services/menu.ashx
the id is the text....

$(this).text() returns the text, which is also the id.

so, I thought it should work.
leakim971

no you need to add # before :
$("#DivTree").jstree("check_node", "#" + $(this).text());

Open in new window

Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
Evan Cutler

ASKER
ASKER CERTIFIED SOLUTION
leakim971

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Evan Cutler

ASKER
YOU ARE AWESOME!!!!!!!!!!
I wish I could give you more points....
leakim971

;-))))
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.