Creating a list where one element must have a different template


#1

Hello, I’m new to Ember.

I have a list of elements (ember model) where one element must be rendered using a different template. I’ve been reading through Ember’s documentation and believe that Creating a custom Ember.CollectionView is the way .

App.PendingListView = Ember.CollectionView.extend({
   createChildView: function(viewClass, attrs) {
       if (attrs.content.isConfirmed) {
           viewClass = App.FirstView;
       } else {
           viewClass = App.SecondView;
       }
       return this._super(viewClass, attrs);
    }   
});

//Template
{{view 'pending-list'}}

I get my the content (model in the route) as follows.

App.PendingRoute = Ember.Route.extend({
    model: function() {
        return this.store.find('pendingList');
    },                                                      
  }); 

However, I don’t know how to pass this content to the CollectionView. My CollectionView renders nothing because content is null.


#2

Check out the discourse search feature - it does exactly what you need


#3

Thanks for your reply @Wayne_Douglas.

I checked out Discourse’s search, but I couldn’t figure out how the code is passing the content to the view: https://github.com/discourse/discourse/blob/master/app/assets/javascripts/discourse/views/search-results-type.js.es6. So, I continued searching on Google and found out this question on StackOverflow: http://stackoverflow.com/questions/12493693/get-content-in-view-from-contentbinding

You can use contentBinding property {{view ‘pending-traders’ contentBinding=“controller”}}. In this case, using contentBinding=“Controller”, I could pass my content (model PendingList) to the CollectionView.

I didn’t find any reference to contentBinding or controllerBinding on Ember’s docs.


Why there are not references to contentBinding or controllerBinding in Ember's Docs?