我有一个包含文本字段的组件,例如
<div>
{{input type='text' insert-newline='postMessage' class="form-control" autofocus="true"}}
<input type="hidden" name="uid" value={{room.uid}}/>
</div>
具有此代码段的组件位于名为room
export default Ember.Route.extend({
model(params){
this.store.findRecord('room', params.uid);
}
});
要处理input
中的操作,我为房间创建了一个控制器:
app/controllers/room.js
import Ember from 'ember';
export default Ember.Controller.extend({
actions: {
postMessage(params){
console.log(params);
}
}
});
但是当我点击回车时,我收到了这个错误:
Uncaught Error: <chathub-ember@component:chat-room::ember1071> had no action handler for: postMessage
我也尝试将这个动作放在路线上但没有奏效
答案 0 :(得分:1)
在room.hbs文件中,
{{my-component myAction='postMessage'}}
然后在my-component.js
import Ember from 'ember';
export default Ember.Component.extend({
actions: {
postMessage(params) {
this.sendAction('myAction', params);
}
}
})