我正在使用 Ember's Getting Started Guide创建一个 TodoMVC .即使我严格按照说明进行操作,我仍然停留在 creating a new model instance .
当我输入一个新的待办事项并按回车键时,我得到以下控制台输出:
Uncaught Error: Nothing handled the action 'createTodo'. If you did handle the action, this error can be caused by returning true from an action handler in a controller, causing the action to bubble. ember.min.js:18
我的 js/controllers/todos_controller.js
看起来像这样:
Todos.TodosController = Ember.ArrayController.extend({
actions: {
createTodo: function() {
// Get the todo title set by the "New Todo" text field
var title = this.get('newTitle');
if (!title.trim()) { return; }
// Create the new Todo model
var todo = this.store.createRecord('todo', {
title: title,
isCompleted: false
});
// Clear the "New Todo" text field
this.set('newTitle', '');
// Save the new model
todo.save();
}
}
});
有什么想法吗?
更新
将我的代码放入 JSFiddle 确实有效:http://jsfiddle.net/narzero/7926x/5/ .我不明白为什么。
我正在使用 Mac OSX 10.9.1。
最佳答案
如果有人还在寻找答案。我遇到了与上述问题相同的问题。
我有由 yeoman 安装的 ember 应用程序。它提供了一个 app.js 文件:
var TodomvcEmber = window.TodomvcEmber = Ember.Application.create();
/* Order and include as you please. */
require('scripts/controllers/*');
require('scripts/store');
require('scripts/models/*');
require('scripts/routes/*');
require('scripts/views/*');
require('scripts/router');
注意到在我的 .tmp/scripts/combined-scripts.js 文件中添加的 Controller 我放在/scripts/controllers/todos_controller.js 中,但没有集成。 在 app.js 文件中,我更改了 require 的顺序(将 Controller 的 require 向下一点)
var TodomvcEmber = window.TodomvcEmber = Ember.Application.create();
/* Order and include as you please. */
require('scripts/store');
require('scripts/models/*');
require('scripts/controllers/*');
require('scripts/routes/*');
require('scripts/views/*');
require('scripts/router');
这对我有用。
关于javascript - Uncaught Error : Nothing handled the action 'createTodo' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23403623/