Object expected at renderItemAsync Error with WinJS.Binding.Template

The following applies to Windows Store Apps using JavaScript:

When trying to add a ListView control with a static data-source of an array of objects and using Binding templates with ListView controls, always remember to have the list item template (WinJS.Binding.Template) before the ListView control in the markup. Otherwise, the solution will error out in the ui.js file at the following line:
[snippet id=”108″]
And the error will have the following stack trace:
[snippet id=”107″]
The reason behind this is that the html element exposed as a list item template is created after the ListView has been created. Typically, when the markup is being rendered at the start of the app, the compiler will start rendering the html markup in the order of appearance, so it hits the ListView control which has its itemTemplate property pointing to another html element exposed as a WinJS.Binding.Template. the compiler tries to render this template but it can’t find it because it hasn’t encountered this element yet in the markup so it will generate an error. look for the html element that is bound as a list item template ListView control with a static datasource of an array of objects.

The following code sample shows how:[snippet id=”106″]


Posted in Windows 8, Windows Development Tagged with: , , ,