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>β
drew covi
source share