Hey!
I have an object on my controller which acts as a hashmap to store some UI state. But I can’t access the values of the hashmap from the view. I scaffolded the app with ember-cli so I have a route, which fetches the data, a hbs-template for the view and a controller. To give you the idea I’ll post a simplified version my code:
ListController:
import Ember from 'ember';
export default Ember.ObjectController.extend({
tenantUsers: [],
sorted: {},
actions: {
sort: function (field) {
if (Ember.isEmpty(this.get('sorted')[field])) {
this.get('sorted')[field] = true;
} else {
this.get('sorted')[field] = !this.get('sorted')[field];
}
if (this.get('sorted')[field]) {
this.set('tenantUsers', this.get('tenantUsers').sortBy(field));
} else {
this.set('tenantUsers', this.get('tenantUsers').toArray().reverse());
}
}
}
});
list.hbs
[table]
[tr]
[th {{action 'sort' 'email' }} {{bind-attr class=":sortable sorted.email:sortable--asc" }}]{{t "userlist.th.email" }} {{ sorted.email }}[/th]
[th {{action 'sort' 'firstname' }} {{bind-attr class=":sortable sorted.firstname:sortable--asc" }}]{{t "userlist.th.firstname" }}[/th]
[th {{action 'sort' 'lastname' }} {{bind-attr class=":sortable sorted.lastname:sortable--asc" }}]{{t "userlist.th.lastname" }}[/th]
[th {{action 'sort' 'username' }} {{bind-attr class=":sortable sorted.username:sortable--asc" }}]{{t "userlist.th.username" }}[/th]
[th {{action 'sort' 'registerDate' }} {{bind-attr class=":sortable sorted.registerDate:sortable--asc" }}]{{t "userlist.th.registerdate" }}[/th]
[th][/th]
[/tr]
{{#each user in tenantUsers }}
[tr]
[td]{{user.email}}[/td]
[td]{{user.firstname}}[/td]
[td]{{user.lastname}}[/td]
[td]{{user.username}}[/td]
[td]{{locale-datetime user.registerDate}}[/td]
[td {{ action 'showUserInfo' user.id}}][span class="icon-info_32"][/span][/td]
[/tr]
{{/each}}
[/table]
I just want to add a CSS class when one of the properties is sorted ASC. But I dont have access to the value of the sorted hashmap. I think I’m doing something in a totally non-Ember-way. Maybe someone could guid me and tell me if I’m working against Ember.
Thanks Tschoartschi EDIT: for some reasons I can’t paste regular HTML into this post. So I replaced < with [