locked
So oniteminvoked is supposed to fire a function when an item in a ListView is tapped/clicked?

    Question

  • Doesn't seem to be working for me. Not hitting the breakpoint of the invoke function.
    HTML has this ListView below (ListView just has a bunch of rectangle divs right now, nothing special):

    <div id="CategoryListView" data-win-control="WinJS.UI.ListView" data-win-options="{selectionMode: 'none', oniteminvoked: categoryInvoked}" style="width:1110px;height:355px;">
    

    And my .js file has this:

      function categoryInvoked(eventInfo) {
        WinJS.Navigation.navigate("/html/category.html", false);
      }
    
    I tried putting the function in the fragmentLoad as well, but it doesn't work there or outside of it.

    Any tricks I'm missing to catch a click of a ListView?



    • Edited by Harlequin Monday, January 30, 2012 10:10 PM cleanup
    Monday, January 30, 2012 7:30 PM

Answers

  • This worked, just did it in JavaScript:

     

            var theListView = WinJS.UI.getControl(document.getElementById("CategoryListView"));
            theListView.addEventListener("iteminvoked", categoryInvoked, false);
    


    The addeventListener I guess needs that boolean. Most of the examples I found didn't have it, but I guess it's necessary for the invoke.


    • Marked as answer by Harlequin Tuesday, January 31, 2012 4:25 PM
    • Edited by Harlequin Tuesday, January 31, 2012 4:25 PM
    Tuesday, January 31, 2012 4:25 PM

All replies

  • Hey H,

    You probably did not expose the function in your namespace and use namespace resolution to access it.

    See the first and last post in this Forum thread:

    http://social.msdn.microsoft.com/Forums/en-US/winappswithhtml5/thread/00ec9749-7366-4a48-b946-f28bb46bb6cf

    -Jeff

     


    Jeff Sanders (MSFT)
    Tuesday, January 31, 2012 3:13 PM
    Moderator
  • This worked, just did it in JavaScript:

     

            var theListView = WinJS.UI.getControl(document.getElementById("CategoryListView"));
            theListView.addEventListener("iteminvoked", categoryInvoked, false);
    


    The addeventListener I guess needs that boolean. Most of the examples I found didn't have it, but I guess it's necessary for the invoke.


    • Marked as answer by Harlequin Tuesday, January 31, 2012 4:25 PM
    • Edited by Harlequin Tuesday, January 31, 2012 4:25 PM
    Tuesday, January 31, 2012 4:25 PM
  • You can do it that way too, or use the HTML notation as I pointed out.
    Jeff Sanders (MSFT)
    Tuesday, January 31, 2012 4:37 PM
    Moderator