Question

Manuel Alberto Cerdas Salazar on Tue, 27 Nov 2012 21:12:05


Hello:  I'm working with the split app template, and I'm having trouble catching an event, specifically when I try to catch when the user clicks a link.

On my split.html I have this

<divclass="itemtemplate"data-win-control="WinJS.Binding.Template">

    <!--- CODE OMMITTED --->

 <divclass="article-content"data-win-bind="innerHTML: description"></div> 

On my split.js I'm using this code inside the ready function

varcosa = WinJS.Utilities.query("a");

cosa.listen("click",this.navegar,false); //navegar is a function I defined

This works fine if I hard code a tags in my split.html; however the a tags I'm interested in catching are in the data that is fed to the article-content div.  And these are not caught by my JavaScript

Any help will be greatly appreciated


Sponsored



Replies

Manuel Alberto Cerdas Salazar on Fri, 30 Nov 2012 17:22:50


Seems this thing has something to do with asynchronous programming.  Just tried my code with a smaller JSON file and it worked fine. 

Cobra Tap on Sat, 01 Dec 2012 22:31:44


Definitely an async timing bug.
You have to figure out when the render function on the template is run and the element is appended to the window.document.
This is exactly why there is the onactivated handler and a promise returned by WinJS.UI.ProcessAll()...

Manuel Alberto Cerdas Salazar on Sun, 02 Dec 2012 05:47:32


Big thank you!  Seems I have a lot of reading ahead

Manuel Alberto Cerdas Salazar on Mon, 10 Dec 2012 21:07:43


Got it!  Just in case anybody is having the same problem, the event handler has to be placed in the _selectionChanged method located in the split.js file