【发布时间】:2019-06-01 14:53:03
【问题描述】:
所以我在 EmberJS 中有嵌套组件,无法正确处理它们的操作。
我有路由Create 和它的模板组件pixel-grid:
<div class="row">
<div class="col-sm-7">
{{pixel-grid}}
</div>
<div class="col-sm-5">
</div>
</div>
在pixel-grid 模板中,我有一个名为pixel-cell 的组件:
<table class="mx-auto">
{{#each (range 0 panelWidth) as |row|}}
<tr class="table-row">
{{#each (range 0 panelHeight) as |cell|}}
<th class="table-cell">
{{pixel-cell onClick=(action 'changeColor')}}
</th>
{{/each}}
</tr>
{{/each}}
</table>
组件pixel-cell 有一个空模板,因为我现在不需要它。在pixel-cell 组件 js 文件中我有:
import Component from '@ember/component';
export default Component.extend({
classNames: ['cell', 'clickable'],
tagName: 'div',
init() {
this._super(...arguments);
},
});
此代码显然无法编译,因为我没有处理此操作。 但是..
我试图在 pixel-cell 中设置操作,但后来 Ember 告诉我 pixel-grid 应该有该操作。
所以我确实将这个 changeColor 操作放入了 pixel-grid -> 这不起作用。
所以我尝试在pixel-cell js 中通过类似的方式来处理这个问题:
click() {
this.sendAction('changeColor');
},
->那不行。
我不知道它应该如何工作;/ 我试图阅读指南,但仍然无法做到。请帮忙。
【问题讨论】:
-
Component.sendAction()已被弃用以支持关闭操作:emberjs.com/deprecations/v3.x/#toc_ember-component-send-action
标签: javascript ember.js components action