我正试图通过两个组件向我的路线发送一个动作,我将触发一个createRecord动作。我一直在控制台。通过链条记录,但我似乎永远不会在路线上。这是我的路线的代码:
import Ember from 'ember';
export default Ember.Route.extend({
store: this.get('store'),
actions: {
createEvent (concert) {
debugger;
console.log(concert, 'events route');
console.log(this.get('store'));
let events = this.get('store').createRecord(concert);
return events.save();
}
}
});
和我的路线模板:
{{display-search-results creatEvent="createEvent"}}
后续组件/组件模板按顺序排列:
display-search-results temp:
{{thumbnail-for-search-results event=event createEvent="createEvent"}}
显示搜索结果组件:
import Ember from 'ember';
export default Ember.Component.extend({
classNames: ['col-md-3'],
actions: {
createEvent(concert) {
console.log(concert, "display-search-results comp");
this.sendAction('createEvent', concert);
}
}
});
thumbnail-for-search-results temp:
<img class='event-pic' src={{event.image_url}} onError="this.src='http://i.imgur.com/r7UiMQr.png';">
<div class="caption">
<h3 class="thumb-title">{{event.title}}</h3>
<p class="event-description">
{{event.venue_name}} <br> {{event.start_time}} <br> <br>{{event.city_name}} <br>
{{event.region_name}} <br>{{event.country_name}}
</p>
<p><a class="btn btn-primary" role="button"{{action "createEvent" concert on="click"}}>>Add Event</a> <a href="#" class="btn btn-default" role="button">Button</a></p>
</div>
thumbnail-for-search-results组件:
import Ember from 'ember';
export default Ember.Component.extend({
classNames: ['thumbnail'],
// concert: this.get('store').find('eventful-event'),
actions: {
createEvent() {
console.log(this.get('event'), "thumb comp")
this.sendAction('createEvent', this.get('event'));
}
}
});
答案 0 :(得分:0)
我认为你的解雇是错误的动作名称,它是createEvent,而不是创建记录。我已经创建了一个用于从组件到路由动作进行交互的余烬。
答案 1 :(得分:0)
这只是因为这里的拼写错误:
{{display-search-results creatEvent="createEvent"}}
使用createEvent
代替creatEvent