如何在dataview上调用onclick函数,
itemTpl: [
'<a onClick="this.getViewController().somefunction({id},{code});" href="#">{code}</a><br/>',
]在viewController中
somefunction: function(){
// some logic
}给出的误差
this.getViewController()不是函数
注意:我不想做MyApp.app.getController() ,因为我有很多ViewControllers,我不能把我所有的逻辑都放在一个核心的contoller上
发布于 2017-02-17 08:42:40
如果确实希望在itemTpl中绑定单击函数,则需要指定在模板中可访问的函数,如下所示:
// 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 文档那里得到的,所以请原谅我犯的错误并纠正我的错误,这样我就可以编辑答案了。
https://stackoverflow.com/questions/42291521
复制相似问题