I have the next route:
Calendar.DateIndexRoute = Ember.Route.extend({
model: function(data) {
return {arr:getCalendar(data),
activeYear: data.year,
activeMonthNumber: data.month,
activeDay: data.day};
},
setupController: function(controller, model) {
controller.set('model', model.arr);
controller.set('activeYear', model.activeYear);
controller.set('activeMonthNumber', model.activeMonthNumber);
controller.set('activeDay', model.activeDay);
}
});
arr
is array of arrays. And in index.html
I do next:
{{#each model}}
<tr>
{{#each}}
{{#view Calendar.DateIndexView}}
{{#if isToday}}
<td class="today">
{{number}}
{{else}}
{{#if isSelected}}
<td class="selected">
{{else}}
<td class="day">
{{/if}}
{{number}}
{{/if}}
</td>
{{/view}}
{{/each}}
</tr>
{{/each}}
But I need to access the fields activeYear
and activeMonth
in each loop:
{{#each model}}
<tr>
{{#each}}
access fields activeYear and activeMonth here
{{/each}}
</tr>
{{/each}}
I tried to use {{with}}
component, but it isn't working. Also, I tried use setupController, and it isn't helping.
I solved this problem as follows:
setupController
from route Resulting code is
{{#each item in model.arr}}
<tr>
{{#each day in item}}
{{#if day.isToday}}
<td class="today" {{action changeDay model.activeYear model.activeMonthNumber day.number}}>
{{day.number}}
{{else}}
{{#if day.isSelected}}
<td class="selected" {{action changeDay model.activeYear model.activeMonthNumber day.number}}>
{{else}}
<td class="day" {{action changeDay model.activeYear model.activeMonthNumber day.number}}>
{{/if}}
{{day.number}}
{{/if}}
</td>
{{/each}}
</tr>
{{/each}}
Your if statements aren't necessary for choosing the classes
App.DayController = Em.ObjectController.extend({
notToday = Ember.computed.not('isToday'),
notSelected = Ember.computed.not('isSelected'),
isSelectedClass = Ember.computed.and('isSelected', 'notToday'),
isNotSelectedClass = Ember.computed.and('notSelected', 'notToday')
});
{{#each day in item itemController='day'}}
<td {{bind-attr class="day.isToday:today day.isSelectedClass:selected day.isNotSelectedClass:day"}} {{action changeDay model.activeYear model.activeMonthNumber day.number}}>
{{day.number}}
</td>
{{/each}}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.