【发布时间】:2013-07-16 15:43:47
【问题描述】:
我刚刚升级到 Knockout.js 2.3.0,现在我收到了这个错误:
You cannot apply bindings multiple times to the same element.
我在 2.2.1 中没有。
单击href 后,我从 MVC 控制器获取部分视图并将其添加到页面中。当我第二次单击链接以获取部分视图时,会发生该错误。我这样做了很多次。
有没有办法清除它并避免抛出新的错误?
这是我的代码:
$.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");
});
});
这是我的 HTML:
<div id="area1">
<!-- grid here with links -->
</div>
<div id="editAssignedPartial"></div>
$(document).ready(function () {
'use strict';
var vm = new Vm();
ko.applyBindings(vm, document.getElementById("area1"));
});
【问题讨论】:
-
stopBindings 是更好的方法...knockmeout.net/2012/05/quick-tip-skip-binding.html
标签: knockout.js