I’ve been using CanJS for a little while and I keep running into the same problem. Say I have a model and I render a view based on that model. Now I want to change the dom elements that were generated while rendering the view somehow (say I have a jQuery plugin that I want to apply to some rendered elements). The problem is that these elements won’t exist yet, they will exist once canJS has rendered them completely.
Here’s an example of what I mean: https://jsfiddle.net/z6q5efwu/
In the example, I render the list of inputs, and I’d like to focus the last one, but I can’t because it hasn’t actually been rendered yet. I’ve looked into some possible solutions to this:
Use the Async Loading
This is the most obvious solution in the demo I linked, but this doesn’t work in all cases. If I want to do the same thing from a change listener on a model, for instance, I run into the same problem but can’t solve it with this.
This seems to be more geared towards doing one action after all templates have finished rendering. It’s not exactly what I’m looking for and I had some trouble getting it to work.
I had some trouble getting this to work as well, from what I gather this will be fired when the element getting rendered is actually rendered on the DOM? This could be what I’m looking for but I couldn’t get a working example going using the documentation.
Hopefully I’ve explained my goal clearly, if not I can elaborate. I feel like I’m missing something, is there a right way to accomplish what I’m looking for?