locked
ListView get item key in eventhandler (oniteminvoked)

    Question

  • How do I get the key of an item in the oniteminvoked handler. I only can get an index in eventinfo (.detail.ItemIndex). The data source is a virtual-interface and loaded from a SQLite database (no static array where you just can get the item by index). I need the key to get the item from the database and show it in a detailed page.

    Wednesday, October 10, 2012 9:02 AM

Answers

  • Hi Bruno,

    This looks correct.

    -Jeff


    Jeff Sanders (MSFT)

    Monday, October 15, 2012 3:45 PM
    Moderator

All replies

  • I have a solution by now but I don't know if it is correct. With having less than 20 records it works perfect. I tried to find out what's the defined behavior of a ListView together with own implementation of the data interface. Unfortunetly I did not find any description what the behavior will/shoud be. Is the following proposed solution correct? 

        function contactItemHandler(eventInfo) {
            var selectIndex = eventInfo.detail.itemIndex;
            var listView = document.getElementById('contactListView').winControl;
            // get the key from database
            contactDataSource.itemFromIndex(selectIndex).then(function (item) {
                nav.navigate("/pages/contactdetail/contactdetail.html", "{ \"key\":" + item.key + "}");
            });
        }

    Sunday, October 14, 2012 2:18 PM
  • Hi Bruno,

    This looks correct.

    -Jeff


    Jeff Sanders (MSFT)

    Monday, October 15, 2012 3:45 PM
    Moderator