首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >未定义不是主干网中的函数错误。

问未定义不是主干网中的函数错误。
EN

Stack Overflow用户
提问于 2014-06-03 06:04:58
回答 1查看 140关注 0票数 0

我有一个html模板,其中包括骨干代码。我是backbone.whenever的新手,我试着运行代码,它显示了一个未定义的未定义的错误不是函数error.Please帮助。

代码语言:javascript
复制
  <!DOCTYPE html>
      <html>
      <head>
        <meta charset="utf-8">
        <title>hello-backbonejs</title>
      </head>
      <body>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
        <script src="http://ajax.cdnjs.com/ajax/libs/json2/20110223/json2.js"></script>
        <script src="http://ajax.cdnjs.com/ajax/libs/underscore.js/1.1.6/underscore-min.js"></script>
        <script src="http://cdnjs.cloudflare.com/ajax/libs/backbone.js/1.1.0/backbone-min.js"></script>



        <script type="text/javascript">
        (function($){
        //ListView class: Our main app view.

      var ListView = Backbone.View.extend({
        el: $('body'), // attaches `this.el` to an existing element.

    //initialize(): Automatically called upon instantiation. Where you make all types of bindings, excluding UI events, such as clicks, etc.

        initialize: function(){
          _.bindAll(this, 'render'); // fixes loss of context for 'this' within methods

           this.render(); // not all views are self-rendering. This one is.
        },

    //render(): Function in charge of rendering the entire view in this.el. Needs to be manually called by the user.

        render: function(){
          $(this.el).append("<ul> <li>hello world</li> </ul>");
        }
      });

    //listView instance: Instantiate main app view.

      var listView = new ListView();
        })(jQuery);
        </script>
      </body>
      </html>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-06-03 06:21:35

这个问题是由旧版本的underscore.js引起的。将其更改为较新版本后,错误就消失了,您的代码也可以工作了。

http://jsfiddle.net/3dH24/4/

演示中使用的下划线版本:

代码语言:javascript
复制
//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.6.0/underscore-min.js

如果您查看jsFiddle上左侧手风琴菜单中的外部参考资料,您可以看到导入的文件(在头中)。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24008152

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档