0

私は次のことを行っていますが、メソッドとthisのコンテキストから objを取得できません。これは私がhttp://www.adobe.com/devnet/html5/articles/flame-on-a-beginners-guide-to-emberjs.htmlから取っている例ですsearchAgainremoveUser

     <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.context中身は未定SearchAgainとさせて頂きます。removeUser誰かがこれについて私を助けることができますか?

4

1 に答える 1

0

解決策を見つけました。これが他の人にも役立つことを願っています:

  • のメソッドは、recentUsersController実際にはビューではなくイベントを受け取ります (これは記事の間違いだと思います)。
  • {{each}}口ひげは、ループしているオブジェクトの識別子を宣言するために読む必要が{{#each user in App.recentUsersController.reverse}}あります
  • をループしている間recentUsers、そのような識別子は{{action}}口ひげの中に追加する必要があります(例:{{action "removeUser" "user" target="App.recentUsersController"}}
于 2012-12-10T06:08:01.597 に答える