Note that there are some explanatory texts on larger screens.

plurals
  1. POChaining Knockout Custom Bindings
    primarykey
    data
    text
    <p>I have a Knockout custom binding handler that I want to call the foreach bindings functionality on within it and then call a callback function afterwards. I keep getting a "Uncaught Error: You cannot apply bindings multiple times to the same element. " error now as I try to do this.</p> <p>My custom binding is pretty simple (typescript):</p> <pre><code>/// &lt;reference path="knockout.d.ts" /&gt; ko.bindingHandlers["postForeach"] = { init: function (element, valueAccessor, allBindingsAccessor, viewModel, bindingContext) { if (!allBindingsAccessor().postForeachCallback) throw "Callback not defined for postForeach binding!"; //call foreach init functionality ko.bindingHandlers['foreach'].init(element, valueAccessor, allBindingsAccessor, viewModel, bindingContext); }, update: function (element, valueAccessor, allBindingsAccessor, viewModel, bindingContext) { //call foreach update functionality ko.bindingHandlers['foreach'].update(element, valueAccessor, allBindingsAccessor, viewModel, bindingContext); //call callback allBindingsAccessor().postForeachCallback(); } }; </code></pre> <p>Is there something I am missing in constructing this?</p> <p>Thanks!</p> <p>EDIT:</p> <p>Callback Function</p> <pre><code>self.populateMainContentWindow = function () { var dataTable = $(this.tableId).dataTable(); dataTable.fnDestroy(); // create the datatable var actualTable = this.jQuery(this.tableId); if (actualTable.length == 0) { return false; } // create the data table with options var newDataTable = actualTable.dataTable(this.options); // always set the width afterwards actualTable.css("width", "100%"); }; </code></pre> <p>Data Bind Signature (which is within a 'with' binding):</p> <pre><code>postForeach: array, postForeachCallback: $parent.viewModel().populateMainContentWindow </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload