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

Accessing ICollections Variable in ClientTemplate

2 Answers 72 Views
ListView
This is a migrated thread and some comments may be shown as answers.
S
Top achievements
Rank 1
S asked on 11 Jul 2017, 06:16 PM

Hello-

I am having an issue accessing my ICollection <Image> Images in the ClientTemplate. It is accessible from the kendo datasource, but not in the ClientTemplate script; however, all of other variables of a different type from my class are accessible. The Image class has a member of type string called "name". My script to access that variable is below. When I load this page, the ListView comes up empty.

 

<script type="text/x-kendo-tmpl" id="template">
        <div id="product">   
            <dl id="itemDetails">
                <dt>ImageName:</dt>              
                <dd>#:Images[0].Name#</dd>            
            </dl>
        </div>
</script>

 

How I successfully access the variable from the dataSource:

function x () {
            var index = this.select().index();
            var dataItem = this.dataSource.view()[index];
             
            $("#ImageName").html(dataItem.Images[0].name);
}

 

How does my syntax need to change to access it in the ClientTemplate script?

Thank you for the help,

S

2 Answers, 1 is accepted

Sort by
0
S
Top achievements
Rank 1
answered on 11 Jul 2017, 06:21 PM
A note about my post above, the capitalization of "name" isn't significant to the issue, but rather a typo when I asked the question.
0
Viktor Tachev
Telerik team
answered on 14 Jul 2017, 01:04 PM
Hi,

The Kendo DataSource supports flat data. Using complex objects with the components could result in unexpected behavior in some scenarios.

In order to show the data as expected I can recommend flattening the data before sending it to the client. 

Furthermore, check out the approach suggested in the article below. Give it a try and let me know how it works for you.



Regards,
Viktor Tachev
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
ListView
Asked by
S
Top achievements
Rank 1
Answers by
S
Top achievements
Rank 1
Viktor Tachev
Telerik team
Share this question
or