我router.js:Ember JS:如何在父組件中設置屬性?
Router.map(function() {
this.route('dashboard', { path: '/' });
this.route('list', { path: '/list/:list_id' }, function() {
this.route('prospect', { path: 'prospect/:prospect_id', resetNamespace: true });
});
});
list.hbs:
<div class="content-wrapper">
<div class="content">
{{prospect-list name=model.name prospects=model.prospects openProspect="openProspect"}}
</div>
</div>
{{outlet}}
前景-list.hbs:
{{#each prospects as |prospect|}}
{{prospect-item prospect=prospect openedId=openedProspectId openProspect="openProspect"}}
{{/each}}
前景,item.hbs
<td>{{prospect.firstName}}</td>
<td>{{prospect.list.name}}</td>
組件/前景列表。 JS
import Ember from 'ember';
export default Ember.Component.extend({
openedProspectId: 0,
actions: {
openProspect(prospect) {
this.set('openedProspectId', prospect.get('id'));
this.sendAction('openProspect', prospect);
}
}
});
組件/前景-list.js
import Ember from 'ember';
export default Ember.Component.extend({
tagName: 'tr',
classNameBindings: ['isOpen:success'],
isOpen: Ember.computed('openedId', function() {
return this.get('openedId') == this.get('prospect').id;
}),
click: function(ev) {
var target = $(ev.target);
if(!target.is('input'))
{
this.sendAction('openProspect', this.get('prospect'));
}
}
});
一切工作很好,當我在瀏覽器中啓動應用程序與http://localhost:4200,但是當我從http://localhost:4200/list/27/prospect/88當前加載的前景(ID爲88)開始不在預期列表中突出顯示,因爲初始打開的縱向標記集爲0.
在這種情況下,我如何設置opensProspectId?
我能得到像路由/ prospect.js這些ID:
import Ember from 'ember';
import AuthenticatedRouteMixin from 'ember-simple-auth/mixins/authenticated-route-mixin';
export default Ember.Route.extend(AuthenticatedRouteMixin, {
model(params) {
return this.store.findRecord('prospect', params.prospect_id);
},
afterModel(params) {
console.log(params.id);
}
});
但我該如何將它傳遞給openedProspectId?還是應該以另一種方式構建我的應用程序?
謝謝。我使用鏈接到幫助器,這解決了我的問題,因爲它會在應用程序加載時設置活動類。 – Dmytro