我的应用程序(repo)中有一条路线,我在那里获取属于用户的预订,我还在请求中包含租借和租赁。租约。现在,出租(属于预订)有很多出租率,而出租率属于用户。在模板中,我有一个接受预订的组件和rentalRating作为争论。如何获得属于预订和当前用户的评级?
预订路线:
import Ember from 'ember';
import AuthenticatedRouteMixin from 'ember-simple-auth/mixins/authenticated-route-mixin';
export default Ember.Route.extend(AuthenticatedRouteMixin, {
sessionAccount: Ember.inject.service(),
model() {
const currentUser = this.get('sessionAccount.currentUser');
return this.get('store').query('booking', {
filter: {
'user_id': currentUser.id
},
include: 'rental,rental.rental-ratings'
});
}
});
预订模板:
<h1>Your bookings</h1>
{{#each model as |booking|}}
{{booking-card booking=booking rating="??? what goes here???"}}
{{/each}}
答案 0 :(得分:1)
实现这一目标的最简单方法是使用ember-composable-helpers。
将sessionAccount
服务移动到控制器中。在您的模板中,您只需使用filter-by
帮助程序:
{{#each model as |booking|}}
{{booking-card booking=booking rating=(get (filter-by "user" sessionAccount.user booking.rental.rentalRatings) "firstObject")}}
{{/each}}