This is a migrated thread and some comments may be shown as answers.

[Solved] Client side binding problem with TreeView

7 Answers 184 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Eugene
Top achievements
Rank 1
Eugene asked on 12 May 2010, 11:41 PM
Greetings,
   After the following controller code is executed, and the javascript code

$(

'#TreeView').data('tTreeView').bindTo([result]);

 

is executed, the value of the root node is, lets say 600.

 

// Create the root node, which is the workspace within the site

 

tvItem0 =

new TreeViewItemModel();

 

tvItem0.Text = ws.Name;

tvItem0.Value = ws.ID.ToString();

tvItem0.Expanded =

true;

 

tvItem0.LoadOnDemand =

true;

 

tvItem0.Enabled =

true;

 

 

foreach (PageContent pc in ws.Children)

 

{

tvItem =

new TreeViewItemModel();

 

tvItem.Text = pc.Name;

tvItem.Value = pc.ID.ToString();

tvItem.Expanded =

true;

 

tvItem.LoadOnDemand =

true;

 

tvItem.Enabled =

true;

 

tvItem0.Items.Add(tvItem);

}

 

return new JsonResult { Data = tvItem0 };

But, when the tree appears and the root node is clicked on, the root value is incorrect; it is the value of the first child under the root node, say 519.  The following javascript code is used to retrieve the value of the node:

 

 

var nodeSelected = $(e.item).closest('.t-item').find(':input[name*="Value"]').val();

Can the controller code above that creates the tree nodes be used to do client side binding?  It just has a root node and children below it.

The code is using version 2010.1.309 of the MVC TreeView control, jquery 1.4.2, running under Microsoft Vista Business N, Service Pack 2.

 

 

 

Thanks in advance,
Eugene

 


7 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 13 May 2010, 08:29 AM
Hi Eugene,

Upgrading to Q1 2010 SP1 (assembly version 2010.1.416) should address this problem. Then please use the provided getItemValue JavaScript to obtain the node value:

var nodeSelected = treeView.getItemValue($(e.item));


Regards,
Atanas Korchev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Sam Daniels
Top achievements
Rank 1
answered on 13 May 2010, 01:55 PM
Is there any way to upgrade to the SP1 before purchasing?  I am considering purchasing soon, but we are in the process of doing a proof of concept and the only version I seem to have access to is 2010.1.309.

Thanks.
0
Atanas Korchev
Telerik team
answered on 13 May 2010, 02:33 PM
Hello Sam Daniels,

You can download from here.

Regards,
Atanas Korchev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Sam Daniels
Top achievements
Rank 1
answered on 13 May 2010, 02:57 PM
Thank you.
0
Eugene
Top achievements
Rank 1
answered on 13 May 2010, 06:26 PM
Thanks Atanas.  Upgrading did the trick. But I wonder why $('#TreeView').getItemValue($(e.item)); crashes with the error:
Microsoft JScript runtime error: Object doesn't support this property or method, whereas using a variable first as in var treeview = $('#TreeView').data('tTreeView'); treeview.getItemValue($(e.item)); did indeed work.

Sincerely and thanks again,
Eugene
0
Atanas Korchev
Telerik team
answered on 13 May 2010, 07:54 PM
Hi Eugene,

This error is natural as $('#TreeView') is a jQuery object whereas $('#TreeView').data('tTreeView') is the TreeView client side object (totally different thing).

All the best,
Atanas Korchev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Eugene
Top achievements
Rank 1
answered on 14 May 2010, 02:42 PM
Thanks Atanas.
Tags
TreeView
Asked by
Eugene
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Sam Daniels
Top achievements
Rank 1
Eugene
Top achievements
Rank 1
Share this question
or