is there a way to bind elements from inside of custom binding? For example I have custom binding and bind to it observable array of items:
var someArrayOfItems = ko.observableArray(['item1', 'item2', 'item3']);
...
<div data-bind="myBinding: someArrayOfItems"></div>
Now I would like myBinding to list all the elements from 'someArrayOfItems' inside the div element it was bound to like:
<ul data-bind="foreach: someArrayOfItems">
<li>
<span data-bind="text: $data"></span>
</li>
</ul>
Is it possible to make such operation using a custom binding? Thanks for any help.
You can use the function
ko.applyBindingsToNode
to dynamically add a binding to an element.In your case, you would need to also populate the contents with an appropriate "template".
For example, you could do something like:
Sample here: http://jsfiddle.net/rniemeyer/z458E/