knockoutJS execute callback after foreach finishes rendering

knockoutJS execute callback after foreach finishes rendering

Asked on December 21, 2018 in knockout js.
Add Comment


  • 1 Answer(s)

        For executing the callback only once use the  custom binding .

        The code is similar to this :

    ko.bindingHandlers.doSomething = {
        update: function(element, valueAccessor) {
            ko.utils.unwrapObservable(valueAccessor()); //grab a dependency to the obs array
            //do something based on "element" (the container)
        }
    }
    

        Use the code like this :

    <ul data-bind="foreach: items, doSomething: items">
        <li>...</li>
    </ul>
    

        doSomething require to get their own dependency to items, as foreach updates within their own computed observable and in KO 3.0 bindings will be not dependent .

         The user can transfer the choice to doSomething and then get a dependency by entering the observableArray via allBindingsAccessor().foreach , If the user always couple it with foreach.

    Answered on December 21, 2018.
    Add Comment


  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.