Hi,
I can't figure out how to add my own properties to a treeview template. I am using a model 'NodeViewModel' which gets populated in my controller from a back end data source, and I want some of the properties to be used in the template HTML. However, the template only allows setting of basic properties (such as text, Id and expanded) because they use the TreeViewItem class which my model maps to (I'm not sure if there's another way of doing it, that's just from the examples I've worked with). Below I have pasted by view and my model - any help is appreciated. I am trying to get the property RiskColour to bleed through into the template displayed.
Any help would be massively appreciated.
Thanks, Mark
MY MODEL :-
public class NodeViewModel
{
public NodeViewModel()
{
this.Expanded = true;
this.Children = new List<NodeViewModel>();
}
public int Id { get; set; }
public string Title { get; set; }
public bool Expanded { get; set; }
public int SortOrder { get; set; }
public string RiskColour { get; set; } ====== THIS IS MY PROPERTY I AM HAVING ISSUES WITH
public bool HasChildren
{
get { return Children.Any(); }
}
public IList<NodeViewModel> Children { get; private set; }
}
MY VIEW :-
<script id="TreeViewTemplate" type="text/kendo-ui-template">
<div style="text-align:left;">
#: item.text # ASDAFF
</div>
</script>
<script>
function onSelect(e) {
alert($(e.node).data("id"));
}
</script>
@( Html.Kendo().TreeView()
.Name("TreeViewTemplateBiding")
// .Template("#: item.text #")
// .TemplateId("TreeViewTemplate")
.HtmlAttributes(new { @class = "alignleft" })
.Events(events => events
.Select("onSelect")
)
.BindTo((IEnumerable<TEAMSPortalV2.Models.NodeViewModel>)ViewBag.Tree, (NavigationBindingFactory<TreeViewItem> mappings) =>
{
mappings.For<TEAMSPortalV2.Models.NodeViewModel>(binding => binding.ItemDataBound((item, node) =>
{
item.Id = node.Id.ToString();
item.Text = node.Title;
item.Expanded = node.Expanded;
item.RiskColour = node.RiskColour; ====== THIS IS MY PROPERTY I AM HAVING ISSUES WITH - item.RiskColour generates an error :(
})
.Children(node => node.Children));
})
)