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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T02:42:38+00:00 2026-06-03T02:42:38+00:00

Am using template binding to bind the DIV’s to main div . $(function ()

  • 0

Am using template binding to bind the DIV’s to main div .

 $(function () {
 function MyViewModel() {
      this.collection = {
        List: [{ name: 'amar', progress: 20 },
               { name: 'vijay', progress: 50}]
      }
}
createDiv();
ko.applyBindings(new MyViewModel());
});

var createDiv = function (ItemList) {
    var maindiv = $("<div  data-bind=\"template: { name: 'task-template', foreach: collection.List  }\" ></div>");
    maindiv.appendTo("#TestDiv");
}
<script type="text/html" id="task-template">
  <div id="Div1" style="width: 95px; height: 31px; border-width: 1px; border-style:solid; background-color: #00FF00;"  data-bind="text: name" ></div>
 </script>

The above code is working fine. I just want to know is there any way to use “createDiv” method’s argument “ItemList” in data-bind template like below.

var maindiv = $("<div  data-bind=\"template: { name: 'task-template', foreach: ItemList  }\" ></div>");

I don’t want use MyViewModel’s data in template’s foreach , i just want to use my method argument there. Is there any way to do this ?

  • 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-03T02:42:41+00:00Added an answer on June 3, 2026 at 2:42 am

    You can call applyBindings on that div separately.

    $(function () {
     function MyViewModel() {
          this.collection = {
            List: [{ name: 'amar', progress: 20 },
                   { name: 'vijay', progress: 50}]
          }
    }
    var vm = new MyViewModel();
    ko.applyBindings(vm);
    createDiv(vm.collection);
    });
    
    var createDiv = function (ItemList) {
        var maindiv = $("<div  data-bind=\"template: { name: 'task-template', foreach: ItemList  }\" ></div>");
        maindiv.appendTo("#TestDiv");
        ko.applyBindings({ItemList: ItemList}, maindiv[0]);
    }
    <script type="text/html" id="task-template">
      <div id="Div1" style="width: 95px; height: 31px; border-width: 1px; border-style:solid; background-color: #00FF00;"  data-bind="text: name" ></div>
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a KnockoutJS template that looks something like this: <div data-bind=template: {name: 'testTemplate',
After loading a PHP template (using jQuery's load function), this simple script won't make
I'm trying to define a function using template template parameters (I just want to
I am using a template function and I am passing and I may be
I'm using a template and the titles are inside a div . I want
I'm using a listbox with a template like the following. <ListBox.ItemTemplate> <DataTemplate> <Image Source={Binding}
We need to assign the Name property at the runtime using the data binding.
I have a toolbar using ItemsSource bind to my main VM. each item is
I am trying to bind a collection to wpf TreeView control using data templates.
I'm making a Perl website, and I'll using Template Toolkit (for the view), a

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.