ember.js - Ember - how to use pushObject on nested data object? -
i can push new object jobs , jobproducts array post how create nested models in ember.js?
but cannot seem push new allocations or deliverys. have included json object below.
any advice appreciated, put fiddle of when moment.
cheers
app.jobs = [ { id: 0, jobtitle: "this job", jobproducts: [ { id: 0, producttitle: "product 1", allocations:[ { id: 0, allocationtitle: "allocation 1", deliverys:[ { id: 0, deliverytitle: "delivery 1" }, { id: 1, deliverytitle: "delivery 2" } ] }, { id: 1, allocationtitle: "allocation 2", deliverys:[ { id: 0, deliverytitle: "delivery 3" }, { id: 1, deliverytitle: "delivery 4" } ] } ] }, { id: 1, producttitle: "product 2", allocations:[ { id: 0, allocationtitle: "allocation 3", deliverys:[ { id: 0, deliverytitle: "delivery 5" }, { id: 1, deliverytitle: "delivery 6" } ] }, { id: 1, allocationtitle: "allocation 4", deliverys:[ { id: 0, deliverytitle: "delivery 7" }, { id: 1, deliverytitle: "delivery 8" } ] } ] } ] } ];
the short:
here example how might it: http://jsbin.com/esixeh/7/edit
the long:
in example find code lines below, scary works:
app.get('jobs').objectat(0).jobproducts.objectat(0).allocations.objectat(0).deliverys.pushobject({...});
since down json structure, starting app.get('jobs')
objects plain javascript objects , not extend ember.object
cannot use ember methods .get('allocations')
or .get('deliverys')
on them , chain them like:
app.get('jobs').get('jobproducts').get('allocations').get('deliverys');
or
app.get('jobs.jobproducts.allocations.deliverys');
but can still use plain javascript dot notation accessor .allocations
.
on array's can still use ember's .pushobject()
, .objectat()
etc. instead of plain .push()
, because array's augmented framework default see here more info on that.
hope helps.
Comments
Post a Comment