Ember 控制器的奇怪错误
Weird error with Ember controllers
我在 Ember CLI 版本:0.2.3
我目前正在探索 Ember,并尝试一个非常简单的应用程序。
我的 templates/about.hbs
里有这个
<h1>About</h1>
<p>I'll write something interesting here</p>
<button type="btn btn=primary"{{action 'clickMe'}}>Click me!</button>
在我的 controllers/about_controller.js
Blogger.AboutController = Ember.Controller.extend({
actions: {
clickMe: function() {
alert('Something something');
}
}
});
当我单击按钮时出现此错误,我检查了语法但似乎无法发现问题所在。我需要一些新鲜的眼睛。
Uncaught Error: Nothing handled the action 'clickMe'. 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 可能找不到您的控制器。您可以使用 ember inspector. In any case you should be using ES6 conventions inside your ember cli project. You can get to know more about the subject here 对其进行调试。
无论如何,尝试通过键入
使用命令行创建 about
控制器
ember generate controller about
然后手动添加您的操作。
您的程序使用的是 ember cli 还是 Ember 初学者工具包。
如果您使用的是 Ember cli,那么您应该创建如下文件 -
app/templates/about.hbs
app/controllers/about.js
你也应该在 app/router.js 中输入一个条目[我想你一定已经这样做了。]
进入 router.js-
Router.map(function() {
this.route('about');
});
现在你的 template/about.hbs 应该是-
<h1>About</h1>
<p>I'll write something interesting here</p>
<button {{action 'clickMe'}}>Click me!</button>
和 controllers/about.js 应该是-
import Ember from 'ember';
export default Ember.ObjectController.extend({
actions:{
clickMe: function() {
alert('Something something');
}
}
});
完成上述所有更改后,在 CMD 上执行以下命令 -
ember 服务器(这应该启动服务器)
如果您按照上述模式进行操作,您的代码应该可以正常工作。
Ember.
中的命名约定非常重要
我在 Ember CLI 版本:0.2.3
我目前正在探索 Ember,并尝试一个非常简单的应用程序。
我的 templates/about.hbs
里有这个<h1>About</h1>
<p>I'll write something interesting here</p>
<button type="btn btn=primary"{{action 'clickMe'}}>Click me!</button>
在我的 controllers/about_controller.js
Blogger.AboutController = Ember.Controller.extend({
actions: {
clickMe: function() {
alert('Something something');
}
}
});
当我单击按钮时出现此错误,我检查了语法但似乎无法发现问题所在。我需要一些新鲜的眼睛。
Uncaught Error: Nothing handled the action 'clickMe'. 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 可能找不到您的控制器。您可以使用 ember inspector. In any case you should be using ES6 conventions inside your ember cli project. You can get to know more about the subject here 对其进行调试。
无论如何,尝试通过键入
使用命令行创建about
控制器
ember generate controller about
然后手动添加您的操作。
您的程序使用的是 ember cli 还是 Ember 初学者工具包。
如果您使用的是 Ember cli,那么您应该创建如下文件 - app/templates/about.hbs app/controllers/about.js 你也应该在 app/router.js 中输入一个条目[我想你一定已经这样做了。] 进入 router.js-
Router.map(function() {
this.route('about');
});
现在你的 template/about.hbs 应该是-
<h1>About</h1>
<p>I'll write something interesting here</p>
<button {{action 'clickMe'}}>Click me!</button>
和 controllers/about.js 应该是-
import Ember from 'ember';
export default Ember.ObjectController.extend({
actions:{
clickMe: function() {
alert('Something something');
}
}
});
完成上述所有更改后,在 CMD 上执行以下命令 - ember 服务器(这应该启动服务器)
如果您按照上述模式进行操作,您的代码应该可以正常工作。 Ember.
中的命名约定非常重要