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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:38:45+00:00 2026-06-17T08:38:45+00:00

I am trying to write a custom binding called divider. Its simply splice the

  • 0

I am trying to write a custom binding called divider.

Its simply splice the passing observableArray object into smaller arrays and wrap its elements with a template. It is working but i am getting an error :

Uncaught Error: Unable to parse bindings.
Message: ReferenceError: list is not defined;
Bindings value: foreach : list

What is the problem here ? I can’t see 🙂

HTML

<form data-bind="divider : { size : 4, list: controls , templateName : 'unit' }" class="form-horizontal"></form>

<script id="unit" type="text/x-jquery-tmpl">
    <div class="control-group">
      <div class="box" data-bind="template: { name : 'controlTemplate', foreach : $data }"></div> 
    </div>
</script>

<script id="controlTemplate" type="text/x-jquery-tmpl">
  <label data-bind="text:label" class="control-label" />
  <div class="controls">
    : <input data-bind="value:value" type="text" class="input-small"></input>
  </div>
</script>

<script id="dividerTemplate" type="text/x-jquery-tmpl">
    <div class="dividerContainer"  data-bind="foreach : list ">
      <div class="divider" data-bind="template : { name : $parent.name }"></div>               
    </div>
</script>

JAVASCRIPT

function l(log) {
 console.log(log); 
}

function Control(label,value) { 
  var self = this;  
  this.label = ko.observable(label);
  this.value = ko.observable(value);
}

function ViewModel() {

  var self = this;  

  this.controls = ko.observableArray();  

  for(var i=1;i<=10;i++) {
    this.controls.push(new Control('TEST'+i,'VALUE'+i));
  }  
}  

ko.bindingHandlers.divider = {

    init: function (element, valueAccessor, allBindingsAccessor, data, context) {

      var defaultOptions = { size : 5 };
      var options = $.extend(true, defaultOptions, valueAccessor()); 

      var seperatedList = ko.observable([]);

      if( options.list().length > 0 && options.templateName !== null) {

        var length = options.list().length;
        var size = options.size;
        var templateName = options.templateName;

        for(var i=0; i< (length/size); i++)          
                seperatedList().push(options.list.slice(i*size, (i+1)*size) );

        l(ko.toJSON(seperatedList));

        ko.applyBindingsToNode(  $(element).get(0),
                                 {template: { name: 'dividerTemplate' , data : { list: seperatedList , name : templateName}} }
                              );
        }

    }
};

$(document).ready(function(){

  var viewModel = new ViewModel();  
  ko.applyBindings(viewModel);

});

JSFIDDLE

  • 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-17T08:38:46+00:00Added an answer on June 17, 2026 at 8:38 am

    You will want to have your custom binding’s init function return:

          return { controlsDescendantBindings: true };
    

    This makes sure that the main binding loop does not try to apply bindings to the new elements that were rendered as a result of you manually calling the template binding from your binding.

    Some extra information: here and here

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

Sidebar

Related Questions

I'm trying to write a custom adapter to adapt a simple class into a
I'm trying to write a custom powershell script that will create a local user
I am trying to write a custom magento module and i've got it all
I am trying to write a custom tag. I can write attributes; however, I'm
I'm trying to write a custom rendering template for use in the DisplayForm of
I am trying to write a custom script that will keep a list of
I'm trying to write a custom servlet (for AJAX/JSON) in which I would like
I am trying to write a custom select statement in Hibernate using the getHibernateTemplate()
i am trying to write a custom event which should get fire when user
I have been trying to write a custom .screenrc file TEST as follows startup_message

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.