2013-01-18 7 views
5

を動作しません。私は2つの問題でhttp://jsfiddle.net/pF2cF/6/コードを持っていますテキストフィールドのMyButtonが最初にクリックされます(#1が解決された場合)ember.js <ボタン{{アクション}}は></button>が正しく

誰かが解決する手助けはできますか?私は使用するための回避策を持っていますが、私は何が間違って使用しているか分からない。

ありがとうございます!

コードスニペットは、2013年1月14日にそのマスターブランチからember.jsを使用して、次のとおりです。

<script type="text/x-handlebars" data-template-name="myTemplate"> 
     <button {{action clickButton target="App.indexController"}} >MyButton1</button> 
     {{view App.MyView placeholder="Input something 1 and enter"}} 
    </script> 

App = Em.Application.create({ 
    ready: function() { 
    } 
}); 

App.Router.map(function() { 
    this.route("index", { path: "/" }); //master 01142013 syntax 
}); 
App.IndexRoute = Ember.Route.extend({ 
    renderTemplate: function() { 
    this.render('myTemplate', {controller: 'indexController'}); 
    } 
}); 

App.indexController = Ember.Controller.extend({ 
    clickButton: function() { 
    alert("clickButton"); 
    } 
}); 

App.MyView = Em.TextField.extend({ 
    insertNewline: function (evt) { 
    alert("enter pressed"); 
    } 
}); 

答えて

18

あなたは小さなエラーの数を作りました。私はJSBinに作業バージョンを入れました。あらゆる障害を引き起こさなかった

文体の問題:

  • あなたはどんなindexルートを宣言する必要はありません。
  • Applicationに空のreadyメソッドは必要ありません。一般に、起動ロジックをApplicationRoute#setupControllerに入れてください。ここでコントローラにもアクセスできます。
  • 複数のルート間で単一のテンプレートを共有しようとしている場合を除き、テンプレートにはルートと同じ名前を付ける必要があります。この場合は、myTemplateではなく、indexを使用してください。障害に関連

問題:

  • コントローラ名は大文字する必要があります:App.IndexControllerターゲットが現在のコントローラでない場合App.indexController
  • あなたはターゲットを指定しないでください。
  • renderコールには{ controller: 'indexController' }が指定されています。それは{ controller: 'index' }である必要があります。
+0

ありがとうございます!これは素晴らしい作品です! – xinqiu

関連する問題

 関連する問題