Reputation: 4763
How do you go about inserting an advertisement into a ListView. I can conditionally render my item templates and show an add in one, but I don't want to replace an item with an ad. I can also drop a placeholder into my datasource, but then I have to account for that different item in a few places. Is there another way?
Upvotes: 0
Views: 219
Reputation: 648
The WinJS.Binding.List behaves like an array. So let's say you have a list of 10 items, and you want to dynamically ad an advertisement at index "3".
Let's assume you have a variable defined already, named "list" that is your WinJS.Binding.List. You would do
list.splice(3, 0, {ADVERTISEMENT OBJECT HERE});
That should automatically animate your listView to pop in a new element. If it doesn't animate, try one of these http://msdn.microsoft.com/en-us/library/windows/apps/br229780.aspx, you probably want "createAddToListAnimation". It's extremely easy to make animations in WinJS.
I'm guessing your advertisement object would look like {message: "Join XXX today"} or something along those lines.
Upvotes: 1
Reputation: 7292
Those are indeed the two ways you need to do this -- there is no other mechanism that the List View control provides for changing it's visible contents.
If you have grouped data, then you could make a group header the advert; but again, you have to change your data.
Upvotes: 0