Access to data out of foreach knockout

51 views
Skip to first unread message

Андрей Марчишин

unread,
Mar 28, 2015, 2:15:34 PM3/28/15
to knock...@googlegroups.com

I have three similar foreaches, from them I choose items (chekboxes), these items are displayed in data-bind="foreach: SelectedBooks" data-bind="text: bookName".

But, how I can get access to the choses items outside of the used data-bind="foreach: AllBooks" and display data in other place.

Something like this data-bind="text: $root.userName, $root.bookName, $root.someName"with saving of the order of the selected items?

I tried to use this documentations http://knockoutjs.com/documentation/binding-context.html but its still doesn't work.

Example http://jsfiddle.net/falkone/acdbrxy7/

Noirabys

unread,
Apr 23, 2015, 3:48:57 AM4/23/15
to knock...@googlegroups.com
sorry for late reply,

i see two ways:

1. combine the two models into a 'global' lets say application model and applybindings on the model for the complete html structure

or

2. ko.dataFor(domNode) or ko.contextFor(domNode);
  you can access the model bound to a dom node..  dataFor will return the $data context  for that domNode and contextFor will return an object containing all the contextes like $root, $parent etc

best regards,
 noirabys
Reply all
Reply to author
Forward
0 new messages