KnockoutJs v2.3.0:错误您不能多次将绑定应用于同一元素 [英] KnockoutJs v2.3.0 : Error You cannot apply bindings multiple times to the same element

查看:62
本文介绍了KnockoutJs v2.3.0:错误您不能多次将绑定应用于同一元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚升级到2.3.0,现在出现错误

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.

我没有加入2.2.1.

that I wasn't getting in 2.2.1.

我从MVC控制器中获取了部分视图,并在单击href后将其添加到页面中.该错误发生在我第二次单击链接以获取部分视图时.我要这样做多次.

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?

这是我的代码:

$.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");
      });
    });

<div id="editAssignedPartial">
</div>

$(document).ready(function () {
  'use strict';
  var vm = new Vm();
  ko.applyBindings(vm, document.getElementById("area1"));
});

推荐答案

您只需删除绑定,然后再次使用'applyBindings'.

You just have to remove the bindings before you use 'applyBindings' again.

ko.cleanNode($element[0]);

应该可以解决问题. HTH.

should do the trick. HTH.

这篇关于KnockoutJs v2.3.0:错误您不能多次将绑定应用于同一元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆