success callback after knockout.js finishes rendering all the elements

You have the afterRender callback in knockout.js:

foreach: { data: myItems, afterRender: renderedHandler }

Here’s documentation.

Inside your handler check whether the length of the rendered collection is equal to the length of the items collection. If not don’t execute the full rendered logic that you intend to use.

renderedHandler: function (elements, data) {
    if ($('#containerId').children().length === this.myItems().length) {
        // Only now execute handler
    }
}

Leave a Comment