KnockoutJs v2.3.0 : Error You cannot apply bindings multiple times to the same element
KnockoutJs v2.3.0 : Error You cannot apply bindings multiple times to the same element
I've just upgraded to 2.3.0 and now I'm getting the error 'You cannot apply bindings multiple times to the same element.' that I wasn't getting in 2.2.1.
I'm getting a partial view from my MVC controller and adding it to the page after clicking on an href. The error happens the second time I click on the link to get the partial view. I'm doing this multiple times.
Is there a way to clear this out and avoid the new error thrown?
Here's my code:
$.get(url + "GetAssignedCompaniesView?layoutId=" + layoutId + "&noCache=" + new Date().getMilliseconds(), function (result) { $("#editAssignedPartial").html($(result)); showEditAssignedArea(true); $(window.document).ready(function () { // error is thrown here ko.applyBindings(self, window.document.getElementById("editAssigned")); $("#layoutId").attr("value", layoutId); updateTypeHiddenElement.attr("value", "companies"); }); });
$(document).ready(function () { 'use strict'; var vm = new Vm(); ko.applyBindings(vm, document.getElementById("area1")); });
Answer by x0n for KnockoutJs v2.3.0 : Error You cannot apply bindings multiple times to the same element
You should never apply bindings more than once to a view. In 2.2, the behaviour was undefined, but still unsupported. In 2.3, it now correctly shows an error. When using knockout, the goal is to apply bindings once to your page only once then use changes to observables on your viewmodel to change the appearance and behaviour of your page.
Answer by vprasad for KnockoutJs v2.3.0 : Error You cannot apply bindings multiple times to the same element
You just have to remove the bindings before you use 'applyBindings' again.
ko.cleanNode($element[0]);
should do the trick. HTH.
Answer by javad hemati for KnockoutJs v2.3.0 : Error You cannot apply bindings multiple times to the same element
i had the same problem and I solved it.
var vm = new MessagesViewModel() ko.applyBindings(vm) function ShowMessagesList() { vm.getData("MyParams") } setInterval(ShowMessagesList, 10000)
Answer by ClearCloud8 for KnockoutJs v2.3.0 : Error You cannot apply bindings multiple times to the same element
I had this error occur for a different reason.
I created a template for save/cancel buttons that I wanted to appear at top and bottom of the page. It worked at first when I had my template defined inside of a
0 comments:
Post a Comment