我复制了一个knockoutjs的例子:
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-1.8.0.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/knockout/2.2.0/knockout-min.js"></script>
<Meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
<h2>Participants</h2>
Here are the participants:
<div data-bind="template: { name: 'person-template',data: buyer }"></div>
<div data-bind="template: { name: 'person-template',data: seller }"></div>
<script id="person-template" type="text/html">
<h3 data-bind="text: name"></h3>
<p>Credits: <span data-bind="text: credits"></span></p>
</script>
<script type="text/javascript">
function Myviewmodel() {
this.buyer = { name: 'Franklin',credits: 250 };
this.seller = { name: 'Mario',credits: 5800 };
}
ko.applyBindings(new Myviewmodel());
</script>
</html>
当我将jQuery更新为1.9版时,我遇到以下错误:
Uncaught TypeError: Object function (e,t){return new st.fn.init(e,t,X)} has no method 'clean'
如果有人可以解释这个bug是在jQuery还是KO,我会感激的.
解决方法
原因
你没有使用最新版本的Knockout.以前的版本,2.2.0,与jQuery 1.9.x和on不兼容.见this Knockout dev thread:
Knockout 2.2.0 uses jQuery.clean() which is deprecated and does not exist in 1.9.
这意味着Knockout 2.2.0正在调用未定义的jQuery方法,从而触发您指定的JS错误.
解决方案
考虑更新到the latest version of Knockout与jQuery 1.9兼容
>如果不能,请使用添加的jQuery Migrate
plugin
向后兼容到jQuery 1.9
>如果所有其他失败,您将需要恢复到jQuery 1.8