I am having trouble accessing the values of subdocuments from my form inputs in Ember-data.
Using RESTAdapter, I want to construct a record for 'business information' with an embedded subdocument structure that might look something like this:
"businessHours": {
"monday":{
"operating-status": "open",
"from": null,
"to": null
},
"tuesday": {
"operating-status": "open",
"from": null,
"to": null
}
}
Where business hours is just one attribute of the business object. I am attempting to define that subdocument relationship with the following models. Problem is, the form inputs (code below) are not updating the businessHours attribute in the Ember inspector. When I save the record, the entire attribute is null.
In the business model (among all the other attributes):
businessHours: DS.belongsTo('hours', {async: false}),
the 'hours' model:
export default DS.Model.extend({
bizinfo: DS.belongsTo('location.js', {async: false}),
monday: DS.belongsTo('day', {async: false}),
tuesday: DS.belongsTo('day', {async: false}),
wednesday: DS.belongsTo('day', {async: false}),
thursday: DS.belongsTo('day', {async: false}),
friday: DS.belongsTo('day', {async: false}),
saturday: DS.belongsTo('day', {async: false}),
sunday: DS.belongsTo('day', {async: false})
});
And finally the 'day' model:
import DS from 'ember-data';
export default DS.Model.extend({
hours: DS.belongsTo('hours', {async: false}),
operatingStatus: DS.attr('string'),
from: DS.attr(),
to: DS.attr()
});
As for templates, I have a business-hours component and feed it the businessHours portion of the model like this:
<h3>Business Hours</h3>
Then, I set the values on the inputs to equal what I would imagine are those values in the subdocument. Is this where I go wrong?
<tr>
<td>Wednesday</td>
<td><select >
<option value="closed">Closed</option>
<option value="open">Open</option>
<option value="24hr">24hr</option>
</select></td>
<td></td>
<td></td>
</tr>
Thanks much for any help!
Aucun commentaire:
Enregistrer un commentaire