Populating ember.select of parent objects


#1

I have been trying to populate an select option list of available parent objects. I’m not using Ember-Data or any other data framework, I’m loading ajax into standard Ember.Object. I load a list of chapters which will have events attached to them. I want to create a new event, but want the user to have the option of selecting the chapter in the add event template. for this I want to fill a select box with chapter tittles and ids as the value.

I can’t get this to work.

I tried creating a computed property called chapters, that returned the chapters

chapters: function (){
    return App.ChaptersModel.findAll();
}.property()

In the template I do this:

 {{view Ember.Select content=chapters  optionValuePath="content.id" optionLabelPath="content.title"}}

this does not seem to work for me.

I don’t get errors, but the list is empty.

Thanks in advance for any advice.


#2

Is there a reason you are making chapters a property that is observing nothing instead of loading them when the controller or route is instantiated? If ‘chapters’ is a static resource it may be more efficient loading them in setupController on the route and then binding the select to the property on the controller.


#3

The route that serves the template will fill the following

title date body status parent_chapter.

I preset a template with via the AuthorNeweventRoute,

the chapters need to be available on this route or controller, so I though. Can a route have more than one model? or controller? I don’t fully understand the setupController’s function.

This is the route to add an event:

App.AuthorNeweventRoute = Ember.Route.extend({
    model: function(){
        return {
            title: 'New Title',
            status: 'Draft',
            periodStart: '12/12/1994',
            body: 'some html coopy'            
        }
    }
});

And this is the controller that I thought might work with the chapter’s property.

App.AuthorNeweventController = Ember.ObjectController.extend({
chapters: function(){
         return App.ChaptersModel.findAll();
     }.property(),
})

Before the user hits the add event action, they are sitting on a list of chapters, that get loaded via another route. But the add event route is not nested inside this route, I was thinking that I probably should nest them. I was going to try that next.

I’m just starting with ember, and some of the concepts are not sinking in yet.

thanks for the help.


#4

I got this to work using the setupController() method. took a while, but I think I understand why it is needed.

Thanks.