ember.js - Nested json object in ember -
the following link works till positions when add object(company) not displaying anything.
app.jsonobject = { id: 1812, name: 'brokerage account', positions: [ { symbol: 'aapl', quantity: '300', company:[ { no: '1', name: 'test' } ] }, { symbol: 'goog', quantity: '500', company:[ { no: '2', name: 'test123' } ] } ] };
the reason why not working because down json structure have plain javascript objects. ember aware of changes , bindings work need use framework's methods ember.object.create
(like app.account), objectat(0)
, pushobject()
etc. create data structure. way bindings , else work expected.
edit in response last comment
a simplistic straight forward way change code this:
app.account = ember.object.create({ id: 1812, name: 'brokerage account', positions: ember.a([ ember.object.create({ symbol: 'aapl', quantity: '300', company: ember.a([ ember.object.create({ no: '1', name: 'test' }) ]) }), ember.object.create({ symbol: 'goog', quantity: '500', company: ember.a([ ember.object.create({ no: '2', name: 'test123' }) ]) }) ]) });
so can later use framework methods , stuff like:
app.get('account').get('positions').pushobject(ember.object.create({symbol: 'msft', quantity: 200}));
or
app.get('account').get('positions').objectat(0).setproperties({'quantity': 500});
and here updated fiddle: http://jsfiddle.net/wkgkj/3/
note, fiddle working please don't quote me on approach since it's not preferred ember way of building ember applications, made work backup answer :) worth mentioning in fiddle using 'ember 0.9.4
which outdated since version
1.0.0-rc.6.1` around.
hope helps.
Comments
Post a Comment