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

Check/Unchecked TreeView checkboxes with MVVM and SPA

2 Answers 382 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Baloter
Top achievements
Rank 1
Baloter asked on 05 Apr 2013, 08:13 AM
Hi,
I'm using Treeview checkboxes with MVVM and SPA. I have a ListView that contains every checked treeview node element ( a copy , to be precise). The Listview shows them with a remove button in a template. When the user click the remove button , the application deletes it from the ListView ( By removing the element from an observable array),  but  , I  have also  to uncheck this element from the TreeView. The ListView is in different View  from the TreeView. In this situation, my problems are these:

1. When I set the "checked" property from the observableHierarchy object to false, the TreeView doesn't reflect the change, using MVVM I thought that the binding was in both ways.

2. Because The TreeView and the ListView are in differents views (or pages), I can't  use something like this
$("#treeview .k-checkbox input").eq(0).attr("checked", false)
In the moment when the remove button is pressed there wont be #treeview element.

3. Using methods that break the MVVM pattern (I save the uid from the li element and use these as selector like in the point 2 ), I can uncheck  the treeview nodes, but , another problem emerges.  Apparently , using Jquery to uncheck  a node doesn't change the datasource , so for kendo even if the node is unchecked , in the datasource  the "checked" property  for that node remains equals true, so when I re-check the node, the "change" event for the observableHierarchy doesn't fire, because the checked value is already "true".

So there is a easy way to acomplish  these?

2 Answers, 1 is accepted

Sort by
0
Accepted
Alex Gyoshev
Telerik team
answered on 09 Apr 2013, 08:05 AM
Hello Baloter,

You should update the model only (instead of changing the checkboxes state through JavaScript) -- this way, the widgets will behave as expected, and you won't hit problems #2 and #3. I tried reproducing the first problem in the following jsBin to no avail. Please provide a sample that shows the problem so that we can lend a hand.

Kind regards,
Alex Gyoshev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Baloter
Top achievements
Rank 1
answered on 09 Apr 2013, 04:04 PM
Hi Alex ,

A sample won't be necessary. I was accessing to the "checked" property directly.
this.get("hierarchy")[0].checked=true
Thanks, for your help.
Tags
TreeView
Asked by
Baloter
Top achievements
Rank 1
Answers by
Alex Gyoshev
Telerik team
Baloter
Top achievements
Rank 1
Share this question
or