我正在从 SmashingMagazine ( http://coding.smashingmagazine.com/2013/11/07/an-in-depth-introduction-to-ember-js/ ) 学习本教程,当我尝试使用调用自定义操作的按钮时,我不断遇到此错误:
<小时/>Uncaught Error: Nothing handled the action 'edit'. 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.
user.js
Controller :
App.UserController = Ember.ObjectController.extend({
actions: {
edit: function(){
this.transitionToRoute('user.edit');
}
}
});
user.hbs
View :
<div class="user-profile">
<button {{action "edit"}}>Edit</button>
<!--<img {{bind-attr src="avatarUrl"}} alt="User's avatar" />-->
<h2>{{name}}</h2>
<span>{{email}}</span>
<p>{{bio}}</p>
<span>Created {{creationDate}}</span>
</div>
{{outlet}}
user\edit.hbs
View :
<div class="user-edit">
<label>Choose user avatar</label>
{{input value=avatarUrl}}
<label>User name</label>
{{input value=name}}
<label>User email</label>
{{input value=email}}
<label>User short bio</label>
{{textarea value=bio}}
</div>
<小时/>
其余一切都工作正常。我可以显示我的用户列表和个人用户。
谢谢!
最佳答案
我遇到了同样的错误,但原因不同。有使用以下代码的演示视频。
App.FileController = Ember.ObjectController.extend({
isEditing: false,
edit: function () {
this.set('isEditing', true);
},
done: function () {
this.set('isEditing', false);
}
});
如果您从EmberJs website查看此链接您会发现需要将方法包装在 actions
属性中才能使其正常工作。
App.FileController = Ember.ObjectController.extend({
isEditing: false,
actions: { //<------
edit: function() {
this.set('isEditing', true);
},
done: function() {
this.set('isEditing', false);
} //<------
}
});
希望我为您节省了一些时间。
关于javascript - Uncaught Error : Nothing handled the action 'edit' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20777762/