lundi 26 janvier 2015

Access model-attribute in ArrayController

I'd like to add a computed property to a controller containing an attribute from the model. I've got a list of blog-posts belonging to the same category. I added a component rendering breadcrumbs via setting a breadcrumb property in the controller.


Up until now I rendered the category-name in the template via {{ this.firstObject.category.name }}


This doesn't work in the controller. How can I get the model's attributes?


Here's my route and controller so far:


routes/category.js



import Ember from 'ember';

export default Ember.Route.extend({
model: function(params) {
return this.store.find('post', { category: params.category });
}
});


controllers/category.js



import Ember from 'ember';

export default Ember.ArrayController.extend({
breadCrumb: function() {
var posts = this.get('post'); // <-- is empty
console.log(this.firstObject.category.name);
return posts.get(this.firstObject.category.name); // <-- doesn't work
}
});




Aucun commentaire:

Enregistrer un commentaire