Cimm
Cimm

Reputation: 4775

Using a different model in an Ember controller

I am trying to wrap my head around Ember.js but fail to grasp it.

I have a HolidaysNewRoute where I want to show a calendar of this month, you can click on a day to select or deselect it. You would save this to show what dates you will be on holiday for example.

App.HolidaysNewRoute = Ember.Route.extend({});

App.HolidaysNewController = Ember.ArrayController.extend({
  days: function() {
    return [
      new App.Day({index: 1}),
      ...
    ];
  }.property()
});

<script type="text/x-handlebars" id="holidays/new">
   {{#each day in days}}
     {{day}}
   {{/each}}
</script>

This shows me things like <App.Day:ember354:null> in the {{day}} placeholder in my template. Now, I would like to show the day index (1 in this example) so:

 ...snip...
   {{day.index}}
 ...snip...

but Ember complains I am calling index on an undefined object.

What am I doing wrong? Is the general structure what it should be or am I trying to solve the wrong problem? I could rename 'holiday' to 'day' but the resource am I trying to create is a holiday with dates, not a single date.

Upvotes: 0

Views: 25

Answers (1)

panta82
panta82

Reputation: 2721

I'm presuming you created App.Day model using Ember.Data or by extending Ember.Object. In that case, you're creating the instances wrong. Instead of this new App.Day({index: 1}), try this: App.Day.create({index: 1}).

As to whether you're doing things right, hard to say without detailed code review. In what you have posted so far, I haven't seen any red flags.

Upvotes: 1

Related Questions