I have a simple observableArray which contains a lot of user-models.
In the markup, there is a template with a foreach loop which loops the users and outputs them in a simple table. I additionally style the table with a custom scrollbar and some other javascript. So now I have to know when the foreach loop is finished and all the models are added to the DOM.
The problem with the afterRender callback is that it gets called every time something is added, but I need kind of a callback which fires only once.
Your best bet is to use a custom binding. You can either place your custom binding after
foreachin the list of bindings in yourdata-bindor you could execute your code in asetTimeoutto allowforeachto generate the content before your code is executed.Here is a sample that shows running code a single time and running code each time that your observableArray updates: http://jsfiddle.net/rniemeyer/Ampng/
HTML:
JS: