@belgoros wrote:
I’m trying to pass in a
model
containing an array of objects like that:# routes/working-hours.js model() { let monday = EmberObject.create({ id: 1, day: 0, state: 0, opens: this._fromMillisToHuman(32400000), //9:00 am closes: this._fromMillisToHuman(72000000) //8:00 pm }); let tuesday = EmberObject.create({ id: 2, day: 1, state: 0, opens: this._fromMillisToHuman(32400000), //9:00 am closes: this._fromMillisToHuman(72000000) //8:00 pm }); ... // all the days of the week return [monday, tuesday, wednesday, thursday, friday, saturday, sunday]; }, });
from a template to a helper defined as follows:
#helpers/weekday-state.js import { helper } from '@ember/component/helper'; export function weekdayState([model], namedArgs) { return model.findBy('id', namedArgs.weekDay).get('state'); } export default helper(weekdayState);
When I call the helper from the template:
# templates/working-hours.hbs ... {{#each weekdays as |weekday|}} ... {{weekday-state model weekDay=weekday.id}}
I always get
Cannot read property 'get' of undefined
. I get all the 7 days array in the helper and the ids are correct.If I call
model[0].get('state')
it returns the right value.When I call
model.findBy('id', namedArgs.weekDay)
I get an Ember object:
found: <Ember.Object:ember588>
Model I get as parameter looks like this:
<Ember.Object:ember583>,<Ember.Object:ember584>,<Ember.Object:ember585>,<Ember.Object:ember586>,<Ember.Object:ember587>,<Ember.Object:ember588>,<Ember.Object:ember589>
What I’m trying to do is:
- display all the days of the week (Monday through Sunday), row by day along with open/close time and state:
- state: open
- from: 8:00am
- to: 8:00pm
- some of the week days have their working hours saved by the user, some have not.
- set the working hours (open/close time) as well as the corresponding state of the shop (open, closed, divided (has a lunch break)).
See the attached screenshot.
So I have an array of 7 days and another array of 0-7 days for which open/close times were set up. That’s why I’m trying to use
findBy
Array method to check if the week day I have as current in the loop is among the selected by User days.What’s wrong with that ? Can’t I pass in objects to helpers, just primitive data (Strings, Integers…). If so, how to solve this ? Thank you.
Posts: 3
Participants: 2