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

标签 javascript ember.js single-page-application

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

相关文章:

Azure B2C ROPC token 对 Microsoft Graph API 无效(缺少 x5t 声明)

javascript - 将不可选择的文本选项卡添加到 Ext.TabPanel?

javascript - 扩展 Audio/HTMLMediaElement javascript 对象

javascript - 在 JavaScript 中拉伸(stretch)图形以填充 Canvas 元素

model-view-controller - 如何在 Ember 中构建递归 View ?

ember.js - 在路由之间传递隐藏参数

javascript - ember.js - 从任何路由换出嵌套资源

web-applications - 将 Breeze.js 与 Dapper 结合使用

javascript - Angular JS |在 ng-click 三元运算符中传递什么什么都不做

javascript - 在 Handlebars "(generated application controller)"helper 中显示 "#each"而不是值内容