Trying to understand how AddEventListener works... RRS feed

  • Question

  • I understand that a ChangeListenener (on elements in the viewmodel) is a special case of an EventListener.

    i have a browse screen with a product collection and following code:

    myapp.BrowseProducts.created = function (screen) {
        // Write code here.
        screen.Products.addEventListener("oncollectionchange", function (e) {
            console.log("on collection change called"); //seems not be called ??

    From the debug viewer, I learnt there is an oncollectionchange event.

    The above snippet doesn't seem to do anything.

    What am I doing wrong?

    Are there any other notable events that could be used on collections and entities, which can improve my understanding of the html client plumbing?

    paul van bladel

    Saturday, February 15, 2014 8:45 AM


  • HI Paul van bladel

    For the usage of addEventListener, Huy shares her experience on this.

    If you're using addChangeListener / addEventListener in your code, objects on HTML Client have different lifetime. Entity Objects tend to stay around much longer than Screen Objects.

    So if you add event listeners to an Entity Object on a Screen, when that Screen is closed, the listeners are still active and you need to clean up that listener.

    hope it helps.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by Angie Xu Monday, February 24, 2014 1:33 AM
    Tuesday, February 18, 2014 2:56 AM