Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6165303
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T22:08:28+00:00 2026-05-23T22:08:28+00:00

about nested dom bindings http://jsfiddle.net/sxd1140/XWvYk/1/ is only this way https://github.com/hunterloftis/knockout.namespaces or have other way

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T22:08:28+00:00Added an answer on May 23, 2026 at 10:08 pm

    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:

    var viewModel = {
        body: {
            click: function() { alert("body"); }  
        },
        div: {
            click: function() { alert("body"); }  
        }
    };
    
    ko.applyBindings(viewModel);
    

    Now, you would have to bind your clicks to body.click and div.click.

    A typical pattern would be to do something like this:

    var viewModel = {
      body: ko.observable(),
      div: ko.observable()
    };
    

    Now, you would use the template binding, which will not render anything if the observable is null and will allow you to specify click directly instead of div.click, as you would pass the view model as the data parameter 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:

    <div data-bind="template: { name: 'main', data: body, templateOptions: { div: div } }"></div>
    
    <script id="main" type="text/html">
        <button data-bind="click: click">body</button>
        <div id="a" data-bind="template: { name: 'div', data: $item.div }"></div>
    </script>  
    
    <script id="div" type="text/html">
        <button data-bind="click: click">div</button>
    </script>
    

    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/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Could anyone explain what node means in MySQL? This one is talking about nested
This is nested about 10 functions deep, so I'll just paste the relevant bits:
I only need a single value from a specific <td> in the DOM's nested
From my topic over @ jquery: https://forum.jquery.com/topic/multiple-pagebeforecreate-events-triggered-when-jqm-builds-the-page-for-nested-listviews-w-jsfiddle It's understandable now, but a little unintuitive.
I've been thinking about nested try/catch statements and started to think about under which
I have about 200 categories that are nested. I am currently reading the documention
I'm having a problem with Rails 3.2.1, a nested resource keeps complaining about an
There is a lot of posts about nested Ajax problems, but I can't figure
So I have a simple application as in RailsCast about nested forms. and a
I have three questions about three nested loops: for (int x=0; x<400; x++) {

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.