简体   繁体   English

emberjs:当我尝试使用操作助手时,我得到 - Handlebars 错误:无法在 object 上找到属性“操作”

[英]emberjs: when I try to use the action helper, i get - Handlebars error: Could not find property 'action' on object

I have been trying to use the action helper with ember.我一直在尝试将动作助手与余烬一起使用。 I get the following error: Handlebars error: Could not find property 'action' on object.我收到以下错误:Handlebars error: Could not find property 'action' on object。

I think I am following the examples in my simplified view here:我想我在这里按照我的简化视图中的示例进行操作:

<script type="text/x-handlebars" data-template-name="user-edit">
    <p><a href="#" {{action "showUsersList"}}>Back</a></p>
</script>

The view object:视图object:

App.UserEditView = Ember.View.extend({
    templateName: 'user-edit',
    userBinding: 'App.usersController.selectedUser',
    tagName: 'span',
    didInsertElement: function () {
        $('h1').html('Edit User');
        document.title = 'Edit User';
    },
    showUsersList: function(event) {
        App.usersController.showUsersList();
    }
});

Any idea why I cannot use the action helper like in the examples?知道为什么我不能像示例中那样使用动作助手吗?

Thanks, Robert谢谢,罗伯特

You can also simply create the view and append it to the document.您也可以简单地创建视图并将其 append 添加到文档中。 You don't need the second handlebars template.您不需要第二个车把模板。

App.UserEditView = Ember.View.create({
    templateName: 'user-edit',
    userBinding: 'App.usersController.selectedUser',
    tagName: 'span',
    didInsertElement: function () {
        $('h1').html('Edit User');
        document.title = 'Edit User';
    },
    showUsersList: function(event) {
        App.usersController.showUsersList();
    }
}).append();

I trimmed out some of your app-specific logic, but got your action helper working in this fiddle我删除了一些你的应用程序特定的逻辑,但让你的动作助手在这个小提琴中工作

Handlebars :车把

<script type="text/x-handlebars" data-template-name="user-edit">
    <p><a href="#" {{action "showUsersList"}}>Back</a></p>
</script>

<script type="text/x-handlebars" >
  {{view App.UserEditView}}
</script>​

JavaScript : JavaScript :

App = Ember.Application.create({});

App.UserEditView = Ember.View.extend({
    templateName: 'user-edit',
    tagName: 'span',
    showUsersList: function(event) {
        alert('hi');
    }
});​

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM