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

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

问题描述

我复制了一个淘汰赛示例之一:

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:

淘汰赛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 . li>
  2. 如果不能,请使用 jQuery Migrate 插件 ,其中添加了 向后兼容jQuery 1.9
  3. 如果其他所有方法均失败,则需要恢复为 jQuery 1.8
  1. Consider updating to the latest version of Knockout which is compatible with jQuery 1.9
  2. If you can't, use the jQuery Migrate plugin which adds backward-compatibility to jQuery 1.9
  3. If all else fails, you'll need to revert back to jQuery 1.8

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

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