locked
how to change div content with via itemInvoked event in Listview in navigation app

    Question

  • i wrote this code to modify the content of a div in navigation page

    (function () {
        "use strict";
    
        WinJS.UI.Pages.define("/pages/home/home.html", {
            // This function is called whenever a user navigates to this page. It
            // populates the page elements with the app's data.
            ready: function (element, options) {
                // TODO: Initialize the page here.
                var listView = document.getElementById("basicListView");
                listView.addEventListener("iteminvoked", handler);
    
            },
            function handler(eventInfo) {
            var dlg = new Windows.UI.Popups.MessageDialog("Ta-da!", "Ta-da!");
        dlg.showAsync();
    
    }
    
    });
    })();
    

    but then its showing handler declaration as an error

    so i changed it to

    (function () {
        "use strict";
    
        WinJS.UI.Pages.define("/pages/home/home.html", {
            // This function is called whenever a user navigates to this page. It
            // populates the page elements with the app's data.
            ready: function (element, options) {
                // TODO: Initialize the page here.
                var listView = document.getElementById("basicListView");
                listView.addEventListener("iteminvoked", handler);
    
            },
            handler : function(eventInfo) {
            var dlg = new Windows.UI.Popups.MessageDialog("Ta-da!", "Ta-da!");
        dlg.showAsync();
    
    }
    
    });
    })();
    

    now its showing that handler is not declared..... How to fix it?

    Saturday, December 21, 2013 5:41 PM

Answers

  • Using the code above, you can only access the handler function from within the page object, so you need to change the arguments in your addEventListener() call:


        listView
    .addEventListener("iteminvoked", this.handler.bind(this));

    Thursday, January 2, 2014 8:53 PM

All replies

  • Please post an app for reproduction.

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Monday, December 23, 2013 8:18 PM
    Moderator
  • Using the code above, you can only access the handler function from within the page object, so you need to change the arguments in your addEventListener() call:


        listView
    .addEventListener("iteminvoked", this.handler.bind(this));

    Thursday, January 2, 2014 8:53 PM