简体   繁体   English

Backbone.js和Require.js-未捕获的TypeError:对象函数(){return parent.apply(this,arguments); }没有方法“开”

[英]Backbone.js and Require.js - Uncaught TypeError: Object function (){ return parent.apply(this, arguments); } has no method 'on'

I'm putting together a simple todo list app based on some examples to learn about Backbone. 我将根据一些示例来组合一个简单的待办事项列表应用程序,以了解Backbone。 I'm running the code on Django for database and using Tastypie to do the API, and am trying to use Backbone (with RequireJS for AMD) but am having trouble with the following error in my console: 我正在Django上为数据库运行代码,并使用Deliciouspie做API,并尝试使用Backbone(与AMD的RequireJS一起使用),但在控制台中遇到以下错误时遇到麻烦:

Uncaught TypeError: Object function (){ return parent.apply(this, arguments); } has no method 'on'

I think my app is having trouble communicating via the backbone collection,because it seems to get this error at about here in my app.js (main app view): 我认为我的应用无法通过主干集合进行通信,因为似乎在我的app.js(主应用视图)的此处出现此错误:

// Bind relavent events to the todos.
this.listenTo(Todos, "add", this.addOne);
this.listenTo(Todos, "reset", this.addAll);

I've seen some similar issues on here but I'm just breaking into this stuff so an explanation of what's happening would be much appreciated. 我在这里看到过类似的问题,但是我只是涉足这些东西,所以对发生的事情的解释将不胜感激。

collections.js collections.js

define([
  'underscore', 
  'backbone',
  'app/app',
  'app/models/model'
], function(_, Backbone, app, Todo){

    // The collection of our todo models.
    TodoList = Backbone.Collection.extend({
        model: Todo,

        // A catcher for the meta object TastyPie will return.
        meta: {},

        // Set the (relative) url to the API for the item resource.
        url: "/api/item",

        // Our API will return an object with meta, then objects list.
        parse: function(response) {
            this.meta = response.meta;
            return response.objects;
        }
    });

    var Todos = new TodoList();
    return Todos;
});

app.js: app.js:

define([
  'jquery',
  'underscore', 
  'backbone',
  'app/models/model',
  'app/collections/collection',
  'app/views/view'
], function($, _, Backbone, Todos, Todo, TodoList, TodoView){

    // The view for the entire app.
    var AppView = Backbone.View.extend({
        el: "#todo-app",

        // Bind our events.
        events: {
            "keypress #new-todo": "createOnEnter",
        },

        initialize: function() {
            // TastyPie requires us to use a ?format=json param, so we'll
            // set that as a default.
            $.ajaxPrefilter(function(options) {
                _.extend(options, {format: "json"});
            });

            // Bind relavent events to the todos.
            this.listenTo(Todos, "add", this.addOne);
            this.listenTo(Todos, "reset", this.addAll);

            // Cache some of our elements.
            this.$input = this.$("#new-todo");

            // Get our todos from the API!
            Todos.fetch();
        },

        // Crate a new todo when the input has focus and enter key is hit.
        createOnEnter: function(event) {
            var keyCode = event.keyCode || event.which,
                title = this.$input.val().trim();

            // If we haven't hit enter, then continue.
            if (keyCode != 13 || !title) return;

            // Create a new todo.
            Todos.create({title: title, complete: false});

            // Reset the input.
            this.$input.val("");
        },

        // Add a single todo to the list.
        addOne: function(todo) {
            var view = new TodoView({model: todo});
            $("#todo-list").append(view.render().el);
        },

        // Clear the list and add each todo one by one.
        addAll: function() {
            this.$("todo-list").html("");
            Todos.each(this.addOne, this);
        }
    });
    return AppView;
});

The order of definitions and parameters in your app.js file is incorrect, you can try like this: app.js文件中的定义和参数的顺序不正确,您可以尝试如下操作:

define([
  'jquery',
  'underscore', 
  'backbone',
  'app/models/model',
  'app/collections/collection',
  'app/views/view'
], function($, _, Backbone, Todo, Todos, TodoView){

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Backbone Error:Uncaught TypeError:Object function(){parent.apply(this,arguments); 没有&#39;on&#39;方法 - Backbone Error: Uncaught TypeError: Object function (){ parent.apply(this, arguments); } has no method 'on' Require.js:未捕获的TypeError:对象函数…没有方法 - Require.js : Uncaught TypeError: Object function … has no method require.js和bone.js获取未捕获的TypeError - require.js and backbone.js getting Uncaught TypeError Backbone.js未捕获的TypeError:对象[object Array]没有方法&#39;on&#39; - Backbone.js Uncaught TypeError: Object [object Array] has no method 'on' Backbone.js - 未捕获TypeError:对象[object Object]没有方法&#39;apply&#39; - Backbone.js - Uncaught TypeError: Object [object Object] has no method 'apply' Backbone.js:未捕获的TypeError:对象[object Object]没有方法&#39;apply&#39; - Backbone.js: Uncaught TypeError: Object [object Object] has no method 'apply' Backbone.js:未捕获TypeError:对象#<Object>没有方法'get' - Backbone.js: Uncaught TypeError: Object #<Object> has no method 'get' 未捕获的typeerror对象没有方法“ on”:lobb.js - uncaught typeerror object has no method 'on' : backbone.js require.js未捕获的TypeError:对象的属性&#39;$&#39; <Object> 不是一个功能 - require.js Uncaught TypeError: Property '$' of object #<Object> is not a function Require.js未被捕获的TypeError:jqOAuth不是一个函数 - Require.js Uncaught TypeError: jqOAuth is not a function
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM