我有一个应用程序,在搜索时返回一些数据,以便为我的用户显示。当我单击进行搜索时,我收到此错误和操作中的模型对象,不显示填充了信息的模型。关注错误和代码。
Uncaught Error: Nothing handled the action 'doSearchBooking'. If you did handle the action, this error can be caused by returning true from an action handler in a controller, causing the action to bubble.
组件
export default Ember.Component.extend({
actions: {
searchBooking(booking) {
console.log('Component - 6', booking);
this.sendAction('doSearchBooking', booking);
this.set('booking', {});
}
}
});
表单组件
<form class="row" >
<div class="col-sm-3">
{{input type='text' value=booking.doc1 class='form-control'}}
</div>
<div class="col-sm-2">
{{input type='text' value=booking.doc2 class='form-control'}}
</div>
<div class="col-sm-2">
{{input type='text' value=booking.doc3 class='form-control'}}
</div>
<div class="col-sm-3">
{{input type='text' value=booking.idDoc class='form-control'}}
</div>
<div class="col-sm-2 btn-form-pesquisa">
<button class="btn btn-primary" {{action 'searchBooking' booking}}>Search</button>
</div>
</form>
调用组件
{{search-booking booking=model.booking searchBooking='doSearchBooking'}}
我的控制器
export default Ember.Controller.extend({
actions: {
doSearchBooking(booking) {
console.log('controller - 6');
this.sendAction('searchBooking', booking);
}
}
});
我的路线
export default Ember.Route.extend({
model() {
return Ember.RSVP.hash({
data: this.store.createRecord('booking'),
booking: {}
});
},
actions: {
searchBooking(booking) {
let newSearch = this.store.createRecord('booking', {
doc1: booking.doc1,
doc2: booking.doc2,
doc3: booking.doc3,
idDoc : booking.idDoc
});
newSearch.save();
}
}
});
答案 0 :(得分:1)
问题是您将操作传递给组件searchBooking
:
{{search-booking booking=model.booking searchBooking='doSearchBooking'}}
但是你试着在组件中将其称为:
this.sendAction('doSearchBooking', booking);
而是尝试像这样调用它:
this.sendAction('searchBooking', booking);