除非我不明白你在说什么,否则我认为你应该ListObject
扩展Em.ArrayController
而不是Em.Object
. 此外,如果您的财产取决于content
,它应该是.property('content.@each')
。如果您正在使用路由器,您的模板应该看起来像{{#each thing in controller.knownThings}}
并且您使用{{thin.something}}
,如果不使用路由器,那么{{#each item in App.listObject.knownThings}}
. 此外,openThings
并且closedThings
似乎不正确,您访问它们的方式也是错误的。
我没有为这个特定案例写小提琴,因为我真的不知道你想要做什么,但是看看这个小提琴,特别App.ResourcesController
是模板'resources-view':
控制器:
// ...
App.ResourcesController = Em.ArrayController.extend({
content: [],
categories: ['All', 'Handlebars', 'Ember', 'Ember Data', 'Bootstrap', 'Other'],
categorySelected: 'All',
filtered: function() {
if(this.get('categorySelected') == "All") {
return this.get('content');
} else {
return this.get("content")
.filterProperty(
"category",
this.get('categorySelected')
);
}
}.property('content.@each', 'categorySelected'),
filteredCount: function() {
return this.get('filtered').length;
}.property('content.@each', 'categorySelected'),
hasItems: function() {
return this.get('filtered').length > 0;
}.property('filteredCount')
);
// ...
模板:
<script type="text/x-handlebars" data-template-name="resources-view">
<h1>Ember Resources</h1>
{{#view Bootstrap.Well}}
The following is a list of links to Articles, Blogs, Examples and other types of resources about Ember.js and its eco-system.
{{/view }}
{{view Bootstrap.Pills contentBinding="controller.controllers.resourcesController.categories" selectionBinding="controller.controllers.resourcesController.categorySelected"}}
<i>{{controller.filteredCount}} Item(s) Found</i>
{{#if controller.hasItems}}
<ul>
{{#each resource in controller.filtered}}
<li>
<a {{bindAttr href="resource.url"
target="resource.target"
title="resource.description"}}>
{{resource.htmlText}}
</a>
</li>
{{/each}}
</ul>
{{else}}
{{#view Bootstrap.AlertMessage type="warning"}}
Couldn't find items for {{controller.categorySelected}}
{{/view}}
{{/if}}
</script>