locked
Problems with addChangeListener in HTML Client RRS feed

  • Question

  • I'm adding one ChangeListener watching 'state' of a VisualCollection to perform an operation if length of the data is more than 0, in the home page is not problem and the ChangeListener function perfect, but when I traying to navigate to other page that have similar ChangeListener in the created function does nothing, if I comment the ChangeListener they navigate well, I try using  WinJS.Promise.timeout(5000) but the data is already loaded and the ChangeListener has no effect.

    I think that the ChangeListener is asigned to origin screen and not in the destination screen, is there a way to wait for destination screen finish to load or specify the screen to asign ChangeListener?

    The code I'm using in both screens (the data change in the two, but is the same structure and listener)

    screen.Client.Pub.addChangeListener('state', function () {
                  if (screen.Zon.Pub.state === msls.VisualCollection.State.idle && screen.Zon.Pub.data.length > 0) {
                      screen.findContentItem("name").isVisible = true;
                  }
              });

    Tuesday, June 10, 2014 9:16 PM

Answers

  • I wonder if you're running into an issue with undisposed change listeners in the HTML client.  Unlike the SilverLight client, where each screen has its own active data workspace, the HTML client has one active data workspace shared among all available screens.

    Review Cleaning up change listeners / event handlers in HTML Client, and see if adding these to your two screens is helpful.

    Wednesday, June 11, 2014 3:59 AM

All replies

  • Since it works in created method of one screen, I would triple check the code in the second screen as it should also work. You could try to add the handler in the beforeShown argument of showScreen for second screen. Alternatively, you could disable AutoExecuteQuery and then load the data in screen created method using .then to check the data. HTH, Josh
    Wednesday, June 11, 2014 2:19 AM
  • I wonder if you're running into an issue with undisposed change listeners in the HTML client.  Unlike the SilverLight client, where each screen has its own active data workspace, the HTML client has one active data workspace shared among all available screens.

    Review Cleaning up change listeners / event handlers in HTML Client, and see if adding these to your two screens is helpful.

    Wednesday, June 11, 2014 3:59 AM