success callback after knockout.js finishes rendering all the elements

后端 未结 8 1140
你的背包
你的背包 2020-12-01 04:39

I have implemented a knockout foreach binding, with multiple templates in the same page, one of the example is given here, what I am interested is in finding out when a bloc

8条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-01 04:45

    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
        }
    }
    

提交回复
热议问题