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 7868925
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T01:08:57+00:00 2026-06-03T01:08:57+00:00

Is there a way to apply a single view model to several elements? Basically

  • 0

Is there a way to apply a single view model to several elements?

Basically I have a section of html that the view model (VM1) should be bound to, and I have another view model (VM2) that needs to be bound to a subsection of this. KO doesn’t seem to like this though (I even tried using ko.cleanNode(element) on the subsection). So what I’m trying to do is be more specific in my binding by applying it to each piece that needs it. This is hard to explain without code, so here we go:

<section>
    <ul>
        <li id="one">...</li>
        <li id="two">...</li>
        <li id="three">...</li>
        <li id="diffmodel">...</li>
    </ul>
</section>

What I currently have is VM1 being bound to <section>, and VM2 being bound to #diffmodel, but KO doesn’t seem to like this.

My current objective (and the question proposed) is to apply VM1 to #one, #two, and #three, and VM2 to #diffmodel, but that doesn’t seem to work either (VM1 isn’t being bound at all).

Is there a nice solution to this type of situation?

  • 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-06-03T01:08:59+00:00Added an answer on June 3, 2026 at 1:08 am

    A pretty easy solution is to use a custom binding to prevent the children of an element from being bound.

    It would be something like:

    ko.bindingHandlers.ignoreBindings = {
        init: function() {
            return { controlsDescendantBindings: true };
        }        
    };
    
    var VM1 = {
        valueOne: ko.observable("one"),
        valueTwo: ko.observable("two"),
        valueThree: ko.observable("three")   
    };
    
    var VM2 = {
        different: ko.observable("different")  
    };
    
    ko.applyBindings(VM1);
    ko.applyBindings(VM2, document.getElementById("diffmodel"));
    

    HTML:

    <section>
        <ul>
            <li id="one" data-bind="text: valueOne"></li>
            <li id="two" data-bind="text: valueTwo"></li>
            <li id="three" data-bind="text: valueThree"></li>
            <li data-bind="ignoreBindings: true">
                <div id="diffmodel" data-bind="text: different"></div>
            </li>
        </ul>
    </section>​​
    

    Sample here: http://jsfiddle.net/rniemeyer/FesgK/

    In KO 2.1 (in RC at the moment), the ignoreBindings custom binding could even be used as a containerless binding like: http://jsfiddle.net/rniemeyer/FesgK/1/

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

Sidebar

Related Questions

Is there any way that parent tag styles do not apply to child tag
Is there a way to apply a rule to a single directory and not
Is there a way to apply several different csharp generic constraints to the same
Is there a way to apply a style to all elements of a specific
If I have multiple meshes in a single VBO, is there a way to
Is there a way to apply consistent visual appearance for multiple Windows Forms applications?
Is there a way to apply fade effect after validation. For example the user
Is there a way I can apply '+ to '( 1 2 3)? edit:
Is there any possible way to apply more than CSS to a control through
Is there a way I can apply the login_required decorator to an entire app?

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.