2012-12-10 2 views
0

다음을 수행하지만 searchAgainremoveUser의 컨텍스트에서 this obj를 검색 할 수 없습니다. 이것은 내가 취하는 예입니다. http://www.adobe.com/devnet/html5/articles/flame-on-a-beginners-guide-to-emberjs.htmlEmber에서 ArrayController에서 객체를 삭제하는 방법

 <div id="recent"> 
      <h3>Recent Users</h3> 
      <ol> 
       {{#each App.recentUsersController.reverse}} 
        <li> 
         <a href="#" title="view again" {{action "searchAgain" target="App.recentUsersController"}}>{{this}}</a> - 
         <a href="#" title="remove" {{action "removeUser" target="App.recentUsersController"}}>X</a> 
        </li> 
       {{/each}} 
      </ol> 
     </div> 


    App.recentUsersController = Em.ArrayController.create({ 
content: [], 
addUser: function(name) { 
    if (this.contains(name)) this.removeObject(name); 
    this.pushObject(name); 
}, 
removeUser: function(view){ 
    alert(view.context); 
    this.removeObject(view.context); 
}, 
searchAgain: function(view){ 
    alert(view.context); 
    App.tweetsController.set('username', view.context); 
    App.tweetsController.loadTweets(); 
}, 
reverse: function(){ 
    return this.toArray().reverse(); 
}.property('@each') 

});

view.contextSearchAgainremoveUser은 나를 정의하지 않습니다. 누군가 나를 도와 줄 수 있습니까?

답변

0

나는 해결책을 발견했다. 하기 위해, {{each}} 콧수염이 {{#each user in App.recentUsersController.reverse}}을 읽어야

  • (그리고 나는 그 기사의 실수 생각) 실제로 이벤트가 아닌보기를받는 recentUsersController

    • 방법 : 나도이 도움말 다른 희망 recentUsers 통해 반복하면서
    • 통해 루핑되는 오브젝트 식별자를 선언 이러한 식별자는 콧수염 {{action}} 안에 첨가한다 (예 {{action "removeUser" "user" target="App.recentUsersController"}})
  • 관련 문제