javascript - Uncaught Error : Nothing handled the action 'createTodo'

标签 javascript ember.js handlebars.js

我正在使用 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/

相关文章:

javascript - Handlebars if/else 渲染两个分支

javascript - 如果函数中设置了间隔,如何清除函数组件中的间隔?

javascript - swfobject 不与 html 通信

javascript - Ember Data 的商店 promise 在五次测试中不起作用

javascript - 将 SnapEngage 与 Emberjs 一起使用会导致 JS 错误

php - Ember.js 与 mustache 库的兼容性

javascript - 在 Chrome 中禁止另存为对话框

javascript - 发出 HTTP 请求以抓取内容时重定向

ember.js - 测试时不存在初始化的依赖项

ember.js - 使用 Ember 评估 Handlebars 中的两个条件