【问题标题】:ember action 'Nothing handled the action' within block component块组件中的 ember 操作“没有处理该操作”
【发布时间】:2016-02-28 00:27:39
【问题描述】:

如果我有块形式的组件:

//some-component.hbs
{{#some-component}}
    <button {{action "someAction"}}>test</button>
     <!-- assume you have multiple buttons here with multiple actions -->
{{/some-component}}

//some-component.js
Ember.Component.extend({
    actions: {
        someAction() {
            alert('NOT BEING CALLED');
        }
    }
});

使用 Ember > v2.0。未调用该操作。 如果我称之为:

{{some-component}}

然后放:

<button {{action "someAction"}}>test</button>

在 some-component.hbs 模板中。然后它工作。但这种方式有一些我想避免的缺点。

我查看了文档,但似乎到处都没有这种情况。

【问题讨论】:

    标签: ember.js


    【解决方案1】:

    答案是:

    {{yield this}} 
    

    在模板中

    和:

    {{#some-component as |component|}}
        <button {{action "someAction" target=component}}>TEST</button>
    {{/some-component}}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-10
      • 2013-09-26
      • 1970-01-01
      • 2015-10-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多