I'm working on a Javascript based Windows 8 Metro App. It uses WinJS.UI.ListView
to display a 1 column list of items. I don't know much beyond what was said in the documentation: http://msdn.microsoft.com/en-us/library/windows/apps/br211837.aspx .
How do I customize the list item content, based on the data source? Is there a callback function available, so that for each list item, I get to show/hide certain HTML tags, based on the variable of the corresponding object in the data array?
Like the arrangement in the Examples section of this MSDN documentation, how do I show/hide the img
tag based on whether picture
exists?
On top of that, how do I have variable list item height? Each of my list item will have different height (actually only 2 different heights across all items), based on the show/hide function mentioned above. How to implement this behavior?
Thank you.
The list layout in
WinJS.UI.ListView
does not support items of different heights; it has to be one specific height. If you need that layout, you are going to have to create it yourself. Depending on your data source & number of items this is either trivial, or hard. :)That stated:
itemTemplate
property allows you to supply a function. The details are hereIf you have small datasets (<50), then you can just dynamically create the elements yourself, and use the natural flow of child
div
s to stack your elements one-after the other. The seeds of this solution can be found in my answer here.Let me expand up on the example control, based on a "Blank" WWA Project in VS
Add this code to your
default.js
:And replace the content of
body
with:Finally, in the default.css: