オブジェクトのリストをループしてリンクを作成し、クリックすると、元のオブジェクトにアクセスできる JavaScript コードを呼び出すように思えます。
現時点で最も簡単な方法は、テンプレート コンテキストを新しいカスタム ビューにバインドすることです。この JSFiddle ですべての動作を確認できます: http://jsfiddle.net/67GQb/
テンプレート:
{{#each App.people}}
{{#view App.PersonView contentBinding="this"}}
<a href="#">{{content.fullName}}</a>
{{/view}}
{{/each}}
アプリ コード:
App = SC.Application.create();
App.Person = SC.Object.extend({
fullName: function() {
return this.get('firstName') + ' ' + this.get('lastName');
}.property('firstName', 'lastName')
});
App.people = [
App.Person.create({ firstName: "Yehuda", lastName: "Katz" }),
App.Person.create({ firstName: "Tom", lastName: "Dale" })
];
App.PersonView = SC.View.extend({
mouseDown: function() {
// Note that content is bound to the current template
// context in the template above.
var person = this.get('content');
alert(person.get('firstName'));
}
});
とはいえ、これが少し面倒であることは理解しており、今後数週間で作業するプロセスをさらに合理化するためのいくつかのアイデアがあります.