Вопрос

In KendoUI, how do I select a treeview element if it does not have an ID? Like by the style class or something.

I am writing an MVVM application and there are 2 tabs in a kendo tab strip with each containing a treeview. On selecting one tab, I want it's checkboxes to be updated based on what checkboxes were checked in the other tab and then I want to also call updateIndeterminate() on the treeview it contains within it.

Now, since I am using MVVM, I don't want to access the treeview by it's id. All I can find online on searching is $("#treeView") and in the Telerik forums, the example to call updateIndeterminate() is also this -

var treeview = $("#treeview").data("kendoTreeView");
treeview.updateIndeterminate();

Am I missing something here? I wonder why it's so hard to find.

Это было полезно?

Решение

I suppose the reason why it's hard to find is that it goes against the idea of declarative initialization and the separation of view and model. Your code is not supposed to interact with the widget itself. Instead, all your logic should be wired up in your view model which is bound to the UI.

You can certainly find it without an id, e.g. with something like this:

var treeView = $("ul[data-role=treeview]").first().getKendoTreeView();

or by using the .k-treeview class, but I wouldn't recommend it. If you really need to access it in code, you should give it an id.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top