2015-03-08 3 views
0

Как получить доступ к свойству ID модели при выборе одного из узлов дерева? (Я хочу, чтобы отобразить сведения, основанные на ID следующих в TreeView)Как получить доступ к свойству Model в TreeView на Telerik MVC TreeView (Kendo UI)

 @(Html.Kendo().TreeView() 
       .Name("OrganizationTree") 
       .HtmlAttributes(new { @class = "demo-section" }) 
       .DataTextField("Name") 
       .DragAndDrop(true) 
       .ExpandAll(true) 
       .Events(events => events 
         .Select("onOrgSelect") 
         .Drop("onOrgDrop") 
       ) 
       .DataSource(dataSource => dataSource 
        .Model(m=> m 
         .Id("ID") 
         .HasChildren("HasChildren") 
        ) 
        .Read(read => read 
         .Action("Organizations_Read", "Organizations") 
        ) 
       ) 
     ) 

Вот Javascript функция:

function onOrgSelect(e) 
    { 
     var id = $("#" + e.node.id).?????; 
     GetOrganization(id); 
    } 

ответ

1

Проверьте общие операции тему here.

function onSelect(e) { // this refers to the TreeView object var dataItem = this.dataItem(e.node); 

console.log("Selected node with id=" + dataItem.id); 
} 

$("#treeview").kendoTreeView({ dataSource: [ { id: 1, text: "Item 1", items: [ { id: 3, text: "Item 3" } ] }, { id: 2, text: "Item 2" } ], select: onSelect }); 
+0

Ваш код 'var dataItem ...' в вашем примере должен быть на следующей строке, но да, это сделал трюк! Благодаря! – EdenMachine

Смежные вопросы