Link to home
Create AccountLog in
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?
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

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.
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

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
YOU ARE AWESOME!!!!!!!!!!
I wish I could give you more points....
;-))))