11

Both functions allow to replace/modify binding context and apply it to unbound nodes. "Unbound" means that my own custom bindings that want to use these useful functions must always return { controlsDescendantNodes: true } in init function.

So I cannot understand what the difference between them?

Rango
  • 3,877
  • 2
  • 22
  • 32

1 Answers1

17

When using ko.applyBindingsToNode or in 3.0 ko.applyBindingAccessorsToNode you are able to directly supply the bindings that you want to use for a specific element (so, it would not care about data-bind).

When calling ko.applyBindingsToDecendants you would be applying the bindings that already exist on the child elements (in data-bind attributes by default) of the supplied root node.

RP Niemeyer
  • 114,592
  • 18
  • 291
  • 211
  • 1
    Thank, Ryan. In other words: `ko.applyBindingsToNode` applies a set of bindings to the node, but `ko.applyBindingsToDescendants` applies a context. So node's context doesn't relate to bindings applied. "Context" relates to a viewmodel or to a piece of data with some extra properties ($root, $parent and so on). "Bindings" relates to node's links to that data. Right? – Rango Dec 04 '13 at 19:08
  • right- except `ko.applyBindingsToNode` can also accept a context, if necessary. Otherwise, right. – RP Niemeyer Dec 04 '13 at 22:27