2017-02-17 5 views
0

ItemTplは、関数呼び出しのExtJS私はデータビュー上のonclick関数を呼ぶのですか6

itemTpl: [ 
'<a onClick="this.getViewController().somefunction({id},{code});" href="#">{code}</a><br/>', 
] 

とのViewController

somefunction: function(){ 
// some logic 
} 

this.getViewControllerのエラーを(与えをonclickの)は関数ではありません

注:私は、多くのViewControllersを持っているので、MyApp.app.getController()を行うにwan'tはありませんし、あなたが本当にitemTplにクリック機能をバインドしたい場合、私は、centeral contoller

+0

ext6またはsencha touchを使用していますか?前者の場合は、それは現代的で古典的なツールキットですか? –

答えて

1

にあなたをすべての私のロジックを置くことができません

// Save 'this' scope to me variable for use in XTemplate scope 
var me = this; 

// ... 

itemTpl: [ 
    '<a onClick="this.someFunction();" href="#">{code}</a><br/>', 
    // Defining funtions accessible in the XTemplate 
    { 
     someFunction: function() { 
      // Use 'me' here, because 'this' is XTemplate 
      me.getViewController().someFunction(); 
     } 
    } 
] 
しかし、すべての可能な場合、私はそうのように、代わりの項目にリスナーをクリックし使用します:このようなテンプレートでアクセス可能な機能を指定する必要が

// Save 'this' scope to me variable for use in the item scope 
var me = this; 

// ... 

itemConfig: { 
    listeners: { 
     click: function() { 
      // Use 'me' here, because 'this' is the item 
      me.getViewController().someFunction(); 
     } 
    } 
} 

私は通常ExtJS 4で働いており、ExtJS 6 documentationからちょうどそれを得ましたので、私が作った正解を言い訳して、答えを編集できるようにしてください。

+0

クリックリスナーの問題は、動的なのでパラメータを渡すことができないということです。 最初のアプローチを確認しています... –

+0

いいえ、うまくいきませんでした。なぜ、私はupvotedだが動作していない、同じエラーを返すthis.somefunction関数ではありません –

+0

クリックリスナーを意味しますか?私のサンプルコードでは、リスナーで 'this'を直接使用しないことに関するコメントがあります。代替変数を使用していますか?問題のある最小限の作業コードで作業フィドルを提供できますか? – MarthyM

関連する問題