Treeview with Template - item.text undefined

4 posts, 0 answers
  1. Paul
    Paul avatar
    28 posts
    Member since:
    Mar 2013

    Posted 10 Apr 2015 Link to this post

    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

  2. Laurie
    Laurie avatar
    141 posts
    Member since:
    Feb 2007

    Posted 10 Apr 2015 in reply to Paul Link to this post

    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

  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Alex Gyoshev
    Admin
    Alex Gyoshev avatar
    2500 posts

    Posted 13 Apr 2015 Link to this post

    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.

     
  5. Paul
    Paul avatar
    28 posts
    Member since:
    Mar 2013

    Posted 13 Apr 2015 Link to this post

    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

Back to Top
UI for ASP.NET MVC is VS 2017 Ready