As part of my view I have:
<ul data-bind="foreach: caseStudies"> <li><a data-bind="text: title, attr: { href: caseStudyUrl }"></a></li> </ul>
I want to run some 3rd Party code once knockout has updated the DOM.
caseStudies(data); thirdPartyFuncToDoStuffToCaseStudyLinks(); <-- DOM not updated at this point.
Any idea on how I can hook into knockout to call this at the correct time?
KnockoutJS is far from dead, and it's actually still being improved and evolved (see Technical Knockout) but newer frameworks seem a far better bet for our needs, considering activity and performance.
It is very easy to use KnockoutJS. Simply refer the JavaScript file using <script> tag in HTML pages. A page as in the following image will be displayed. Click on download link and you will get the latest knockout.
Using the afterRender
binding can help you.
<ul data-bind="foreach: { data:caseStudies, afterRender:checkToRunThirdPartyFunction }"> <li><a data-bind="text: title, attr: { href: caseStudyUrl }"></a></li> </ul> function checkToRunThirdPartyFunction(element, caseStudy) { if(caseStudies.indexOf(caseStudy) == caseStudies().length - 1){ thirdPartyFuncToDoStuffToCaseStudyLinks(); } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With