1

ビューとコントローラーの両方を備えたEmberアプリケーションがあります。

http://jsfiddle.net/gavriguy/EDr4G/

関連するモデルを変更して、ユーザーがクリックした現在のアイテムを既読としてマークしたいと思います。私は現在、ビューのアイテムのインデックスを計算することでそれを行うことができますが、問題は、ビューのインデックスがそのコントローラーのインデックスと同じであるかどうかを確認できないことです。何かご意見は?

JavaScript

App.tempController = Em.ArrayController.create({
    content: [
        {
        title: 'A',
        unread: true},
    {
        title: 'B',
        unread: true},
    {
        title: 'C',
        unread: false}
    ]
});

App.someItemsView = Ember.CollectionView.create({
    contentBinding: 'App.tempController.content',
    itemViewClass: Ember.View.extend({
        template: Ember.Handlebars.compile('<div>{{content.title}} unread: {{content.unread}}</div>'),
        click: function(event) {
            //How to mark current clicked item as read?
            console.log(this.content);
            console.log(event);
            this.set('content.unread', false);
        }
    })
});​
4

1 に答える 1

2

ハンドラー内clickで、ビューがレンダリングされる配列アイテムへの参照を取得できますthis.get('content')。したがって、を介してフラグを設定できます。http ://jsfiddle.net/pangratz666/t6Nst/this.setPath('content.unread', false)を参照してください。

itemViewClass: Ember.View.extend({
    template: Ember.Handlebars.compile('<div>{{content.title}} unread: {{content.unread}}</div>'),
    click: function(event) {
        // this.content is the item in the array on which this click event occures.
        this.setPath('content.unread', false);
    }
})
于 2012-05-22T20:41:04.057 に答える