locked
How to loop through each indices in a WinJS.UI.ListView to determine if a value already exists. RRS feed

  • Question

  • Hi,

    I would like to loop through all the values in a List View in WinJS to determine if a certain value already exists.

    The List View is already bound to a data source and the template has 3 values. I want to add a new item to this list view but before adding the item, I would like to ensure that no duplicate values will be added to the list view.

    How would I do that.

    Thanks,

    Rajesh.

    Thursday, November 21, 2013 10:44 AM

Answers

  • Hi,

    The trick to find all the elements in a ListView is to select all of them and then work on the selected items. Was able to achieve this after seeing this example "HTML ListView reorder and drag and drop sample"

    Thanks,

    Rajesh.

    Tuesday, November 26, 2013 4:10 AM

All replies

  • Hi Rajesh,

    Basically you can use ListView.itemDataSource() to fetch all the items which belong to the listview, search into the array to see if there exist a target item, if no, push it into the array.

    var itemDataSource = listView.itemDataSource;

    --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.

    Friday, November 22, 2013 6:37 AM
    Moderator
  • Hi,

    The trick to find all the elements in a ListView is to select all of them and then work on the selected items. Was able to achieve this after seeing this example "HTML ListView reorder and drag and drop sample"

    Thanks,

    Rajesh.

    Tuesday, November 26, 2013 4:10 AM