Iterating over an IEnumerable result from a runtime component RRS feed

  • Question

  • Hi there,

    I'm working on presenting some data from a WinRT component to a JS store app and struggling on something I think should be simple!

    My data service has the following method signature:

    public IEnumerable<SurveyViewModel> GetSurveys() {}

    When I call this from JS I'm struggling to work out the best way to bind the contents to my listview. I thought it best to either directly bind the result, or to iterate over the contents and 'push()' each item onto my public WinJS.Binding.List().

    What is the recommended way to approach this? I'm presuming I need to translate the IEnumerable into something array like on the client side.

    Any thoughts? Many thanks,


    • Edited by dougajmcdonald Monday, March 18, 2013 12:35 PM removed inaccurate statement
    Monday, March 18, 2013 12:32 PM

All replies

  • Your type projection should come out as an array in javascript. That can then be passed to the constructor: new WinJS.Binding.List(surveys). Is there a particular reason you are declaring it as IEnumerable instead of List<SurveyViewModel>? That might project better.

    • Proposed as answer by Bryan Thomas Thursday, March 21, 2013 4:47 PM
    Monday, March 18, 2013 5:36 PM
  • Hi Bryan,

    That's done it, IList has come out in array form so I can bind that directly to the listview, the IEnumerable comes out with a .first() function and some reader'esque, moveNext() type functionality.

    Force of habit with the IEnumerable, web background so would tend to return those if I didn't need to do anything fancy when returning the data.



    Tuesday, March 19, 2013 8:32 AM