locked
Randomise itemDataSource in JS & HTML? RRS feed

  • Question

  • In my .js file: 

    WinJS.Namespace.define("DataExample2", publicMembers);
    In my .html file: 
    <div id="basicListView" data-win-control="WinJS.UI.ListView" 
            data-win-options="{itemDataSource:DataExample2.itemList.dataSource, itemTemplate:select('#mediumListIconTextTemplate'), loadingBehavior:'incremental', layout:{type:WinJS.UI.GridLayout}, selectionMode:'none', swipeBehavior:'none'}">
        </div>

    Is there any way to randomise the two underlined snippets above (DataExample2)?

    Should I be attempting to do this using data-win-bind?

    Thanks for reading my question.

    Wednesday, April 3, 2013 12:35 AM

Answers

  • I added this:

    unload: function () {
                dataList.splice(0, dataList.length);
            },

    And my duplicates have gone. Yay!

    • Marked as answer by ViralBeeb Thursday, April 4, 2013 12:48 PM
    Thursday, April 4, 2013 12:48 PM

All replies

  • So, if I understand correctly, you want to dynamically change the data source of the ListView? If that is the case, then see this forum link to find out if it answers your question: http://social.msdn.microsoft.com/Forums/en-US/winappswithhtml5/thread/c240fc59-5d26-4cb7-9f02-b0b9f017c2b7


    @prashantphadke || Windows Store Developer Solutions #WSDevSol || Want more solutions? See our blog! http://aka.ms/t4vuvz

    Wednesday, April 3, 2013 11:29 PM
    Moderator
  • Thanks for the advice.

    My code looks like this:

    var dataArray = [];
        var title, desc, url, img;
        var dataList = new WinJS.Binding.List(dataArray);
        dataList.notifyReload()
        var publicMembers =
             {
                 itemList: dataList
             };
        WinJS.Namespace.define("DataExample", publicMembers);
        WinJS.UI.processAll();

    I just added the "dataList.notifyReload()", it now fades to black and refreshes when I go back to the page.. However, I am still seeing duplicate entries. It seems every time I navigate away and back to this page it just keeps executing my WinJS.xhr feed and pushing the same data on top of itself.

    The only way I have found around it is by having multiple pages with the DataExample bits mentioned in my first post changed. Could it be related to this line: var dataList = new WinJS.Binding.List(dataArray); ? It mentions in that thread you linked to but I am unsure what exactly is the issue.

    The only thing I can think of is that my feed does only read 20 items. Would it be possible to somehow limit my ListView to only this many items, so when duplicates get added on the end they don't actually appear?

    Any help would be greatly appreciated.

    Thursday, April 4, 2013 1:57 AM
  • I added this:

    unload: function () {
                dataList.splice(0, dataList.length);
            },

    And my duplicates have gone. Yay!

    • Marked as answer by ViralBeeb Thursday, April 4, 2013 12:48 PM
    Thursday, April 4, 2013 12:48 PM