2012-05-22 7 views
1

I이 뷰와 컨트롤러를 모두 가진 엠버 응용 프로그램 :어떻게 목록 항목을 조작하는

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

나는 현재 항목 읽은 상태로 사용자가 클릭을 표시 할 -에 의해 관련 모델을 변경합니다. 현재 뷰의 항목 인덱스를 계산하여이를 수행 할 수 있습니다.하지만 뷰의 인덱스가 해당 컨트롤러의 인덱스와 같은지 확신 할 수 없습니다. 의견이 있으십니까?

자바 스크립트 :

당신의 click 핸들러는 뷰가 this.get('content')를 통해 렌더링되는 배열 항목에 대한 참조를 얻을 수있는 내부
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); 
     } 
    }) 
});​ 

답변

2

. 그래서 당신은 this.setPath('content.unread', false)를 통해 플래그를 설정할 수 있습니다, http://jsfiddle.net/pangratz666/t6Nst/ 참조 :

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); 
    } 
}) 
+0

감사합니다, 그것은 마법처럼 작동합니다 :) – Gavriguy

관련 문제