2012-11-13 4 views
8

現在、FooはBarsタイプの "toMany"プロパティを持つ2つのデータモデルを扱っています。私は現在、2つの選択ボックスを作成しようとしています。最初にFooを配置したときに、そのfooに関連付けられたBarsのみを2番目のリストに絞り込みます。EmberJSコントローラー間のコンテンツのバインド

ここJSFiddle:以下http://jsfiddle.net/drew/6jLCy/

コードが、それは確かに動作しません。これは、最初のもののSelectBox値を設定していますが、2番目の値に対応する棒の値タイトルを設定しません。 HTMLのための

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' 
});​ 

マークアップ:

<script type="text/x-handlebars"> 

    {{view App.SetFooField}} 
    {{view App.SetBarField}} 

</script>​ 

答えて

1

聖なる牛。何年もの間ナットを履いてから、これはまったく新しいエバーデータのバグです。フィクスチャでは、すべてのIDが文字列である必要があります。ちょうど。プレーン。ナッツ。

/************************** 
* 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's object property using ember.js with ember-data

その質問に答えるため@dgebする巨大な感謝。

jsfiddleそれに応じて更新されました。

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

関連する問題