Setting itemController on a filtered subset of an ArrayController's model
Problem Summary: While I can get the children of a collection (defined on
an ArrayController) to use a specific object controller for the
individuals, this doesn't work on filtered subsets of the children.
Short context: I've got Subcriptions, which have Items. I'd like to filter
the subscriptions in my view by type, and have the items within those
subscriptions sort by timestamp. Here's the SubscriptionsController:
Social.SubscriptionsController = Ember.ArrayController.extend({
itemController: 'subscription',
announcements: function() {
return this.get('model').filterBy('kind', 'announcement');
}.property('model.@each.kind'),
user_sites: function() {
return this.get('model').filterBy('kind', 'user');
}.property('model.@each.kind')
});
I've defined SubscriptionController thusly:
Social.SubscriptionController = Ember.ObjectController.extend({
items: function() {
return Ember.ArrayProxy.createWithMixins(Ember.SortableMixin, {
sortProperties: ['post_timestamp'],
sortAscending: false,
content: this.get('content.items')
});
}.property('content.items'),
});
And here's the relevant bit of my handlebars template:
<li> </li>
<ul>
{{#each item in controller.items}}
<li>}</li>
{{/each}}
</ul>
{{/each}}
That code more-or-less does what I want: it renders the items, sorted by
item.post_timestamp, as SubscriptionController defines it.
The problem is if I change to {{#each site in user_sites}}, the
itemController property doesn't seem to magically apply to the sublist. Is
there some kind of Sorcery I should use to inform Ember in my filters that
I'd rather return the controller for the objects rather than the objects
themselves?
No comments:
Post a Comment