jQuery 1.9 的淘汰赛 2.2.0 错误 [英] Knockout 2.2.0 error with jQuery 1.9

查看:24
本文介绍了jQuery 1.9 的淘汰赛 2.2.0 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我复制了一个knockoutjs的例子:

I copied one of examples of 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 版时,出现以下错误:

When I updated jQuery to Version 1.9, I'm got following error:

Uncaught TypeError: Object function (e,t){return new st.fn.init(e,t,X)} has no method 'clean' 

如果有人能解释错误是在 jQuery 还是 KO 中,我将不胜感激.

I'd appreciate it if someone could explain if the bug is in jQuery or KO.

推荐答案

原因

您使用的不是最新版本的 Knockout.之前的版本 2.2.0 与 jQuery 1.9.x 及更高版本不兼容.请参阅此 Knockout 开发线程:

You are not using the most current version of Knockout. The previous version, 2.2.0, is incompatible with jQuery 1.9.x and on. See this Knockout dev thread:

Knockout 2.2.0 使用 jQuery.clean(),它已被弃用并且在 1.9 中不存在.

Knockout 2.2.0 uses jQuery.clean() which is deprecated and does not exist in 1.9.

这意味着 Knockout 2.2.0 正在调用未定义的 jQuery 方法,从而触发您指定的 JS 错误.

This means that Knockout 2.2.0 is calling an undefined jQuery method, thus triggering the JS error you specified.

解决方案

  1. 考虑更新到与 jQuery 1.9 兼容的最新版本的 Knockout莉>
  2. 如果不能,请使用 jQuery Migrate插件,其中添加向后兼容 jQuery 1.9
  3. 如果一切都失败了,你需要恢复到 jQuery1.8

这篇关于jQuery 1.9 的淘汰赛 2.2.0 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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