I'm having some trouble figuring out what to do. Basically I have a 'post' controller that has a function 'imageURL'. This function just takes a string (ex image_1.jpg), and prepends the root path to it (ex images/image_1.png). The problem I'm having is in a parent controller, I only want to display the 4 most recent posts. So the problem is that I cant use "imageURL" on the arranged content. Here is the relevant code.
App.HomeController = Ember.ArrayController.extend({
itemController: 'post',
sortProperties: ['date'],
sortAscending: false,
topPosts: function(){
var content = this.get('arrangedContent');
if(content.length >= 4) content = content.splice(0, 3);
return content;
}.property('content')
});
App.PostController = Ember.Controller.extend({
title: Ember.computed.alias('model.title'),
body: Ember.computed.alias('model.body'),
postDate: Ember.computed.alias('model.postDate'),
imageName: Ember.computed.alias('model.imageName'),
imageUrl: function(){
var id = this.get('model.id');
var postImageRoot = "images/posts/" + id + "/";
var imageName = this.get('model.imageName');
return postImageRoot + imageName;
}.property('imageName')
});
App.Post = DS.Model.extend({
authorId: DS.attr('number'),
author: DS.belongsTo('author'),
title: DS.attr('string'),
body: DS.attr('string'),
snippet: DS.attr('string'),
postDate: DS.attr('date'),
imageName: DS.attr('string')
});
Any help would be appreciated! :D And I have searched for this for a while and haven't found anything that is specifically like this. Would using an array proxy help? or is there something simple I'm missing?
Aucun commentaire:
Enregistrer un commentaire