Knockoutjs "Unable to parse bindings" in plugin with ko.renderTemplate

I created a knockoutjs plugin that ultimately uses ko.renderTemplate to β€œupdate” this binding handler. The code generates the expected result, but also generates the error "Unable to parse bindings."

A reproduction of this problem can be found here http://jsfiddle.net/rhoadsce/VSWK2/ in jsfiddle.

javascript is as follows:

ko.plugin = function(configuration) {
    var self = this;
    self.content = configuration.content || '';
};

ko.bindingHandlers.plugin = {
    update: function(element, valueAccessor, allBindingsAccessor) {
        var viewModel = valueAccessor();

        $(element).append('<div id="pluginContainer"></div>');
        var $container = $(element).children('#pluginContainer');

        ko.renderTemplate("pluginTemplate", viewModel, {}, $container, 'replaceNode');
    }
};

$(function () {
    var vm = (function() {
        var plugin = new ko.plugin({ content: 'test content'});

        return {
            plugin: plugin
        }
    })();

    ko.applyBindings(vm);
});

html is equally simple.

<div data-bind="plugin: plugin"></div>

<script id="pluginTemplate" type="text/html"><span data-bind="text: content"></span></script>
+5
source share
1 answer

, , KO div ( , ), ko.renderTemplate ( ).

, initHandler init { controlsDescendantBindings: true }. KO . .

. : http://knockoutjs.com/documentation/custom-bindings-controlling-descendant-bindings.html

+4

All Articles