Search code examples
knockout.jsjquery-templates

Knockout.js Templates Foreach - force complete re-render


By default, KO "will only render the template for the new item and will insert it into the existing DOM".

Is there a way to disable this feature (as in, force KO to render all items anew)?


Solution

  • If you use jQuery.tmpl's native {{each koObservableArray()}} syntax Knockout cant update single items but must rerender the entire template

    see more here: http://knockoutjs.com/documentation/template-binding.html

    the template engine’s native ‘each’ support: after any change, the template engine is forced to re-render everything because it isn’t aware of KO’s dependency tracking mechanism.

    You only get the "default" behavior if you use the foreach template mode, i.e.:

    <div data-bind='template: { name: "personTemplate", 
                                foreach: someObservableArrayOfPeople }'> </div>