私がよく理解していれば、あなたが望む動作はまさに Ember.js がもたらすものです。
まず、非常に基本的なテンプレートを次に示します。
<script type="text/x-handlebars">
Here, the template is updated each time this property is updated (equivalent to bound property)
{{App.objectTwo.someProperty}}
</script>
これがジャバスクリプトです。ここで本当に ObjectController を使いたいのかわかりませんが、あなたが言及したので、私はそれを使用しました。ObjectController は、そのcontent
プロパティのプロキシとして機能します。これは、 someObjectController.get('count') がcount
コントローラ自体からプロパティを取得しようとすることを意味し、プロパティが存在しない場合、コントローラはcount
そのコンテンツからプロパティを取得します。
App = Ember.Application.create();
App.someObjectController = Ember.ObjectController.create();
App.ObjectOne = Em.Object.extend({
id: null,
count: null
});
App.objectOne = App.ObjectOne.create({
id: 1,
count: 42
});
App.someObjectController.set('content', App.objectOne);
App.ObjectTwo = Ember.Object.extend({
id: null,
someProperty: function(){
return App.someObjectController.get('count')+5;
}.property('App.someObjectController.count')
});
App.objectTwo = App.ObjectTwo.create({
id: 1
});
//in 3 seconds the count property is set to 0. You can see the template is updated
Ember.run.later(function(){
App.objectOne.set('count', 0);
},3000);
動作中の jsfiddle は次のとおりです: http://jsfiddle.net/Sly7/M3727/4/