。 my jsFiddle hereが表示されます。
私はそれはひどく複雑なアプローチではないと思いますが、デザインに関するご質問がある場合はお知らせください。
ハンドルバー:
<script type="text/x-handlebars">
{{#each App.countriesController}}
{{view Ember.Checkbox titleBinding="name" valueBinding="isChecked"}}
{{/each}}
<hr />
{{#each App.countriesController}}
{{#if isChecked}}
{{view App.PartsByCountryView contentBinding="this" partsListBinding="App.partsController"}} <br />
{{/if}}
{{/each}}
</script>
<script type="text/x-handlebars" data-template-name="selected-country">
Country: {{content.name}} <br />
Parts:
{{#each filteredParts}}
{{name}}
{{/each}}
</script>
アプリケーションコード:
window.App = App = Ember.Application.create();
/**************************
* Models
**************************/
App.Country = Ember.Object.extend({
id: null,
name: "",
isChecked: null
});
App.Part = Ember.Object.extend({
id: null,
name: "",
countryId: null
});
/**************************
* Views
**************************/
App.PartsByCountryView = Ember.View.extend({
content: null,
partsList: null,
templateName: 'selected-country',
filteredParts: function() {
return this.get("partsList").filterProperty('countryId', this.getPath('content.id'))
}.property('[email protected]').cacheable()
});
/**************************
* Controllers
**************************/
App.set('countriesController', Ember.ArrayController.create({
content: Ember.A()
}));
App.set('partsController', Ember.ArrayController.create({
content: Ember.A()
}));
/**************************
* App Logic
**************************/
$(function() {
App.get('countriesController').pushObjects([
App.Country.create({id: 1, name: "USA"}),
App.Country.create({id: 2, name: "UK"}),
App.Country.create({id: 3, name: "FR"})
]);
App.get('partsController').pushObjects([
App.Part.create({id: 1, name: "part1", countryId: 1}),
App.Part.create({id: 2, name: "part2", countryId: 1}),
App.Part.create({id: 3, name: "part3", countryId: 1}),
App.Part.create({id: 4, name: "part4", countryId: 2}),
App.Part.create({id: 5, name: "part5", countryId: 2}),
App.Part.create({id: 6, name: "part6", countryId: 2}),
App.Part.create({id: 7, name: "part7", countryId: 2}),
App.Part.create({id: 8, name: "part8", countryId: 3}),
App.Part.create({id: 9, name: "part9", countryId: 3}),
App.Part.create({id: 10, name: "part10", countryId: 3}),
App.Part.create({id: 11, name: "part11", countryId: 3})
]);
});
こんにちは、ロイは素晴らしい答えをありがとう。ちょうど1つの質問:もし私がコンソールに移動し、この 'App.get( 'partsController')のような別の部分を追加しようとすると、pushObjects([ App.Part.create({id:999、name:" part999 "、countryId: 2})]); 'それを関連セクションに追加するにはどうすればよいのですか?もう一度おねがいします。 –
申し訳ありません。filteredParts計算プロパティの定義で監視するプロパティを追加することを忘れてしまいます。私はコードとjsFiddleに更新しました。これで正常にあなたの質問に答えましたか? –
これは非常に迅速でした非常にありがとう、これはcompletetly私の質問に答えています。 –