about nested dom bindings
http://jsfiddle.net/sxd1140/XWvYk/1/
is only this way
https://github.com/hunterloftis/knockout.namespaces
or have other way to solve
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The namespace plug-in is probably the best solution, if you need to have multiple view models that are intermingled.
The typical answer though is to have a main view model with sub-view models off of it and bind to the main one. Like:
Now, you would have to bind your clicks to body.click and div.click.
A typical pattern would be to do something like this:
Now, you would use the template binding, which will not render anything if the observable is null and will allow you to specify
clickdirectly instead ofdiv.click, as you would pass the view model as thedataparameter of the template binding. Then, the UI will update if/when the sub-view models are populated (maybe via AJAX). Bindings would be something like:The “div” view model is passed to the nested template using templateOptions to show that you would not need to rely on viewModel having global scope (don’t need to access viewModel.div from within the nested template).
Sample here: http://jsfiddle.net/rniemeyer/7ZsGK/