Finding items and their keys in a WinJS.Binding.List RRS feed

  • Question

  • Before adding a new item, I want to find if there's a similar item in my WinJS.Binding.List. I could just have a simple for-loop from 0 to list.length and stop as soon as I find anything. But in this case, I also need to save the key for a delayed promise.

    The problem here is that the index of the item may have changed after the delay has passed but if I have the key, I can quickly get the item from the list using that.

    For now, I came up with this little snippet to get the key for a newly inserted item

    addItemGetKeyAsync = (list, item) ->
      promise = new WinJS.Promise (complete) ->
        list.oniteminserted = (e) ->
          list.oniteminserted = null
          setImmediate () ->

    Friday, March 8, 2013 1:57 PM

All replies

  • Is this a question or are you proposing a solution?



    Saturday, March 9, 2013 1:23 AM
  • Hi Marcus,

    Why not store the object when you do the look-up instead of the index and pass the object as the promise's return value?

    Tuesday, March 19, 2013 12:33 PM