Avatar of Evan Cutler
Evan CutlerFlag 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
Avatar of leakim971
leakim971
Flag of Guadeloupe image

>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

Avatar of Evan Cutler
Evan Cutler
Flag of United States of America image

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.
Avatar of leakim971
leakim971
Flag of Guadeloupe image

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

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Evan Cutler
Evan Cutler
Flag of United States of America image

ASKER

YOU ARE AWESOME!!!!!!!!!!
I wish I could give you more points....
Avatar of leakim971
leakim971
Flag of Guadeloupe image

;-))))
ASP.NET
ASP.NET

The successor to Active Server Pages, ASP.NET websites utilize the .NET framework to produce dynamic, data and content-driven web applications and services. ASP.NET code can be written using any .NET supported language. As of 2009, ASP.NET can also apply the Model-View-Controller (MVC) pattern to web applications

128K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo