"Uncaught TypeError: undefined is not a function" - 初学者 Backbone.js 应用程序
"Uncaught TypeError: undefined is not a function" - 初学者 Backbone.js 应用程序
我正在使用Backbone设置一个非常简单的应用程序,但是出现了一个错误。
Uncaught TypeError: undefined is not a function example_app.js:7 ExampleApp.initialize example_app.js:7 (anonymous function)
这是错误在Chrome Inspector中显示的位置(init文件 - example_app.js):
var ExampleApp = { Models: {}, Collections: {}, Views: {}, Routers: {}, initialize: function() { var tasks = new ExampleApp.Collections.Tasks(data.tasks); new ExampleApp.Routers.Tasks({ tasks: tasks }); Backbone.history.start(); } };
这是我的tasks index.haml文件
- content_for :javascript do - javascript_tag do ExampleApp.initialize({ tasks: #{raw @tasks.to_json} }); = yield :javascript
models / task.js
var Task = Backbone.Model.extend({});
collections / tasks.js
var Tasks = Backbone.Collection.extend({ model: Task, url: '/tasks' });
routers / tasks.js
ExampleApp.Routers.Tasks = Backbone.Router.extend({ routes: { "": "index" }, index: function() { alert('test'); // var view = new ExampleApp.Views.TaskIndex({ collection: ExampleApp.tasks }); // $('body').html(view.render().$el); } });
这里有证据证明我正在调用所有的文件(我认为):
有任何想法吗?谢谢!