プロパティを使用してバインドできます。
この方法:
MyApp.websites = [];
MyApp.websites.push(Ember.Object.create({
name: "Stackoverflow"
}));
MyApp.websites.push(Ember.Object.create({
name: "Serverfault"
}));
MyApp.mainController = Ember.Object.create({
currentWebsiteIndex: 0,
currentWebsite: function() {
return MyApp.websites[this.get("currentWebsiteIndex")];
}.property("currentWebsiteIndex")
});
MyApp.favorite = Ember.Object.create({
// how should this be bound to a specific element of MyApp.websites?
nameBinding: "MyApp.mainController.currentWebsite.name"
});
これは単なるアイデアを実証することである、より良い実装は次のようになります。
MyApp.websites = Ember.ArrayProxy.create({
content: [],
currentWebsiteIndex: 0,
currentWebsite: function() {
return this.objectAt(this.get("currentWebsiteIndex"));
}.property("currentWebsiteIndex")
});
MyApp.websites.pushObject(Ember.Object.create({
name: "Stackoverflow"
}));
MyApp.websites.pushObject(Ember.Object.create({
name: "Serverfault"
}));
MyApp.favorite = Ember.Object.create({
// how should this be bound to a specific element of MyApp.websites?
nameBinding: "MyApp.websites.currentWebsite.name"
});
あなたが '特定' とはどういう意味ですか?特定の意味は、配列の最初の項目ですか? – pangratz
@pangratz - 配列内のどの項目でも可能です。私は主に、これがEmberによってサポートされているかどうか、もしそうなら、最良の方法に興味があります。 –