EmberJS content for linking between controllers

I am currently working with two data models where Foo has a "toMany" property of type Bars. Now I'm trying to create two selection windows in which, when the first is filled with Foo, it displays the second list of only bars associated with this foo.

JSFiddle Here: http://jsfiddle.net/drew/6jLCy/

The code is below, but it certainly doesn't work. It comes to setting SelectBox values ​​for the first, but does not populate the second with the corresponding bar values ​​headers.

App = Em.Application.create(); App.store = DS.Store.create({ revision: 7, adapter: DS.fixtureAdapter }); /************************** * Models **************************/ App.Foo = DS.Model.extend({ bars: DS.hasMany('App.Bar'), title: DS.attr('string') }); App.Bar = DS.Model.extend({ foos: DS.hasMany('App.Foo'), title: DS.attr('string') }); /************************** * Fixtures **************************/ App.Foo.FIXTURES = [ { id: 0, title: 'Footitle 1', bars: [0,1] }, { id: 1, title: 'Footitle 2', bars: [0,1,2] } ]; App.Bar.FIXTURES = [ { id: 0, title: 'Bartitle 1', },{ id: 1, title: 'Bartitle 2' },{ id: 2, title: 'Bartitle 3' } ]; /************************** * Views **************************/ App.SetFooField = Em.Select.extend({ contentBinding: 'App.fooController', valueBinding: 'content.selected', optionLabelPath: 'content.title' }); App.SetBarField = Em.Select.extend({ contentBinding: 'App.barController', valueBinding: 'content.selected', optionLabelPath: 'content.title' }); /************************** * Controllers **************************/ App.fooController = Em.ArrayController.create({ content: App.store.findAll(App.Foo) }); App.barController = Em.ArrayController.create({ contentBinding: 'App.fooController.selected.bars' });​ 

Markup for html:

 <script type="text/x-handlebars"> {{view App.SetFooField}} {{view App.SetBarField}} </script>​ 
+8
javascript model-view-controller binding
source share
1 answer

Holy cow. after many days almost nuts, it turns out that this is completely a mistake in the latest ember data. in devices, all identifiers must be strings. just. plain. nuts.

 /************************** * Fixtures **************************/ App.Foo.FIXTURES = [ { id: '0', title: 'Footitle 1', bars: ['0','1'] }, { id: '1', title: 'Footitle 2', bars: ['0','1','2'] } ]; App.Bar.FIXTURES = [ { id: '0', title: 'Bartitle 1', },{ id: '1', title: 'Bartitle 2' },{ id: '2', title: 'Bartitle 3' } ]; 

failed to get embedded object property using ember.js with ember data

Thank you so much @dgeb for answering this question.

jsfiddle respectively.

http://jsfiddle.net/drew/6jLCy/

+1
source share

All Articles