所以,这就是我的模型的样子(由夹具数据表示):
var posts = [{
id: 'b026324c6904b2a9',
title: "My new front door",
author: { name: "Matthieu" },
date: new Date('2013-10-28T12:19:30.789'),
status: 'new',
hidden_message: "hidden1"
}, {
id: '26ab0db90d72e28a',
title: "Best pizza in town",
author: { name: "Harry" },
date: new Date('2013-10-28T12:19:30.789'),
status: '',
hidden_message: "hidden2"
}, {
id: '6d7fce9fee471194',
title: "Skateboard dreamland",
author: { name: "Matthieu" },
date: new Date('2013-10-28T12:19:30.789'),
status: 'solved',
hidden_message: "hidden3"
}, {
id: '48a24b70a0b37653',
title: "my house looks like a pumpkin",
author: { name: "Harry" },
date: new Date('2013-10-28T12:19:30.789'),
status: '',
hidden_message: "hidden4"
}];
我的路线:
App.IndexRoute = Ember.Route.extend({
model: function() {
return posts;
}
});
而且,如果相应的帖子是新的,我希望能够在模板中显示某段 HTML,如果已解决,我希望能够显示不同的 HTML,如果状态为空白则什么都没有。在我看来,似乎最好的方法是使用{{#if}}
帮助器,但这不会进行相等比较,它只能采用布尔变量。所以,我想做这样的事情:
App.IndexController = Ember.ArrayController.extend({
isNew: function(val) {
if(this.get('currentitem.status') === 'new') {
return true;
}
return false;
}.property('isNew')
});
但我不知道如何在模板中选择 {{#each}} 当前正在访问的项目。这甚至可能吗,如果可以,我该怎么做(或类似的事情)?
谢谢大家!