我升级到了 knockout.js 2.3.0,现在我得到了错误Uncaught Error: You cannot apply bindings multiple times to the same element
。应用绑定第二次发生在renderTemplate
下面,无论如何要修复它?
ko.bindingHandlers.eventsMap = {
update: function (element, valueAccessor, allBindingsAccessor, viewModel, bindingContext) {
var accessor = valueAccessor();
ko.renderTemplate(accessor.name, accessor.data, {}, element, 'replaceChildren');
}
};
<div id="events-template" data-bind="eventsMap: { data: eventsMap.currentLocation, name: 'event-template'}"></div>
<script type="text/html" id="event-template">
<!-- ko if: $data -->
<div><b data-bind="html: $data.City"></b></div><hr/>
<div class="events-list" data-bind="with: $data.Events">
<div data-bind="foreach: { data: $data, afterRender: function(element, index, data) { $(element).filter('.span12').find('a[rel!=nofollow]').attr('target', '_blank') }}">
@Html.Partial(MVC.Shared.Views.Controls.Events)
</div>
</div>
<!-- /ko -->
</script>