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

Treeview with Template - item.text undefined

3 Answers 225 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Paul
Top achievements
Rank 1
Paul asked on 10 Apr 2015, 02:44 PM

Hi there,

I am attempting to get the Treeview template to work, similar to the demo for the MVC treeview:

<script id="treeview-template" type="text/kendo-ui-template">
    #: item.text #
    # if (!item.items) { #
    <a class='delete-link' href='\#'></a>
    # } #
</script>
 
<div class="row">
    <div class="form-group col-md-12">
        @(Html.Kendo().TreeView()
            .Name("treeview")
            .TemplateId("treeview-template")
            .DataTextField("Name")
            .DragAndDrop(true)
            .DataSource(dataSource => dataSource
                .Read(read => read
                    .Action("Parties", "TreeView")
                )
            )
            .Events(events => events
                .Drop("onDrop")
            )
        )
    </div>
</div>

However, the item.text expression always evaluates as undefined - not sure what I am doing wrong? If I remove this, the item.items expression on the next line is correctly evaluated.

Thanks,

 Paul

3 Answers, 1 is accepted

Sort by
0
Laurie
Top achievements
Rank 2
answered on 10 Apr 2015, 07:39 PM

Paul,

What is the name of the datasource value you wish to display.  If it is not "text", it will not work. I ran into this same issue earlier today and had to change mine to item.name and, voila!

Best of luck!

Laurie

0
Alex Gyoshev
Telerik team
answered on 13 Apr 2015, 10:53 AM

Hello Paul,

Laurie is right. From the TreeView definition, it appears that the data item field that you want to access is Name (what is specified in the DataTextField). The problem should be resolved if you use item.Name instead.

Regards,
Alex Gyoshev
Telerik
 

See What's Next in App Development. Register for TelerikNEXT.

 
0
Paul
Top achievements
Rank 1
answered on 13 Apr 2015, 12:44 PM

Hi there,

I could have sworn that I tried "item.Name" several times before starting this post and it hadn't worked. Of course, it's working now - thanks!

 

Paul

Tags
TreeView
Asked by
Paul
Top achievements
Rank 1
Answers by
Laurie
Top achievements
Rank 2
Alex Gyoshev
Telerik team
Paul
Top achievements
Rank 1
Share this question
or