Knockout.js: ko.applyBindings (viewModel) & # 8594; is there a complete event for applyBinding?

I have several knockoutjs foreach template bindings that create about 100 <div class='item' /> in different positions throughout my page - everything works fine, except that my subsequent jQuery calls don't work if I don't stop in the debugger and don't wait a second before jquery binding:

 ko.applyBindings(viewModel); $(".item").draggable(); 

I was looking for a dataBound event that I could use to apply bindings AFTER the viewModel was bound, but I did not find anything.

+6
source share
1 answer

As Tyrsius mentions, you can use the afterRender handler, you can also use the afterAd handler depending on whether you want to add / remove items from your list. They are covered as foreach , and template document bindings.

You can also write your own binding to do the same as in this example . I recommend this as the most supported and reusable option, but sometimes it overflows.

However, if you want to use draggable, there is an excellent custom binding that you can possibly adapt.

Hope this helps.

+1
source

Source: https://habr.com/ru/post/916923/


All Articles