我是Ember.js的新手并且在苦苦挣扎。我如何展示分类为“代码”的内容?
var posts = [{
category: 'Code',
id: 'cssbestpractices',
title: "CSS Best Practices",
date: { weekday: "Friday", month: "November", day: "1", year: "2013" }
}, {
category: 'Code',
id: 'namingfiles',
title: "Naming Files",
date: { weekday: "Thursday", month: "October", day: "24", year: "2013" }
}, {
category: 'Pizza',
id: 'seo-copy-block',
title: "SEO Copy Block",
date: { weekday: "Tuesday", month: "November", day: "5", year: "2013" }
}];
我认为我可以做一些简单的事情......
{{#each posts is category.Code}}
<li>{{#link-to 'post' this}}{{title}}{{/link-to}}</li>
{{/each}}
...但我必须遗漏一些东西。我的谷歌搜索没有成功,因为我不熟悉Ember.js的术语。这是我在JSFiddle(and full page view)所处的位置。我真的很感激任何帮助。
答案 0 :(得分:1)
您可以使用filterBy计算的宏来执行此操作:
App.PostsController = Ember.ArrayController.extend({
codePosts: Ember.computed.filterBy('model', 'category', 'Code')
});
您更新的jsfiddle http://jsfiddle.net/marciojunior/BZwQL/