locked
WinJS List Filling with reverse data

    Question

  • I'm having an issue with populating my lists with data.

    The lists are bound to a list view element and are declared in a public namespace etc.

    I have a function I want to call to populate with new data,

    function loadData() {

    for (var i in data) {

             var dataNode = {

                     userName: data[i].username

                    };                   

    itemList.push(dataNode);               

    }                             

    itemList = itemList.reverse();

    }

    As you can see the above code is meant to repopulate the list then reverse it.

    However this just has the effect of my data containing one reverse listed concatenated witht he original list.

    Why is this? and what's the best solution to this issue?

    I have also tried to fill a tempArray with the data then set

    itemList = new WinJS.UI.List(templist.reverse());
    However this just causes the list to contain no data at all.



    Tuesday, December 24, 2013 12:34 PM

Answers

  • Hi BradStevenon,

    However this just has the effect of my data containing one reverse listed concatenated with the original list.

    -> Why not clear your list before you insert something?

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Wednesday, December 25, 2013 3:27 AM
    Moderator
  • Try this
    var templist = [];
    
    for (var i in data) {      
    
    var dataNode = {
                    userName: data[i].username
                };
                templist.push(dataNode);
            }
    
    var itemList = templist.reverse();
    


    Nazia

    Thursday, December 26, 2013 5:00 AM

All replies

  • Hi BradStevenon,

    However this just has the effect of my data containing one reverse listed concatenated with the original list.

    -> Why not clear your list before you insert something?

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Wednesday, December 25, 2013 3:27 AM
    Moderator
  • Try this
    var templist = [];
    
    for (var i in data) {      
    
    var dataNode = {
                    userName: data[i].username
                };
                templist.push(dataNode);
            }
    
    var itemList = templist.reverse();
    


    Nazia

    Thursday, December 26, 2013 5:00 AM