Zach
Zach

Reputation: 5885

How to set the data of WinJS.UI.Repeater control in JS code?

I'm developing a Windows Store Application using JavaScript.

How to set the data of WinJS.UI.Repeater control in JS code? It's a very easy question but I don't know how to do. This is my HTML:

<div id="imgRepeater" data-win-control="WinJS.UI.Repeater">
   <img data-win-bind="src: src" />
</div> 

This is my JS code:

WinJS.UI.Pages.define("/pages/itemDetail/itemDetail.html", {
    ready: function (element, options) {
        var imgSrcArr = 
        [
           { src: '/img/a.jpg' }
        ];            
        var imgRepeater = element.querySelector("#imgRepeater");            
        imgRepeater.data = new WinJS.Binding.List(imgSrcArr);
    }
});

However, no item shows in the repeater div.

What's wrong with the code?

BTW: I don't like the following code:

<div data-win-control="WinJS.UI.Repeater" data-win-options="{data: Data.items}"> 

It seems to use a global variable 'Data.items'.

Upvotes: 0

Views: 1217

Answers (1)

Zach
Zach

Reputation: 5885

I solved it by myself, the last line should be:

imgRepeater.winControl.data = new WinJS.Binding.List(imgSrcArr);

Upvotes: 3

Related Questions