以编程方式创建的 Dojo 按钮 - 范围问题
各位, 我以编程方式创建了一个新的 Dojo 按钮。我正在我的一个自定义道场课程中这样做。创建按钮时,我定义了一个 onClick 方法,单击按钮时应调用该方法。该方法是该类的一部分。我无法调用该方法,因为单击按钮时“this
”的范围不同。有人可以帮我解决这个问题吗?
dojo.declare("CustomClass",null,{
createCustomButton:function(){
var button = new dijit.form.Button({onClick:function(){
removetrack();
testDataGrid.filter({status:"COMPLETED"});
}},"testButton1");
},
removetrack:function(){
//some logic
}
});
var customObj=new CustomClass();
customObj.createCustomButton();
当我单击创建的按钮时,我需要调用 removetrack()
方法。
Dear All,
I've created a new Dojo button programatically. I'm doing that in one of my custom dojo class. While creating the button, I've defined an onClick method which should be called when the button is clicked. This method is part of the class. I'm not able to invoke that method, since the scope of "this
" is different when the button is clicked. Can some one please help me to do fix this?
dojo.declare("CustomClass",null,{
createCustomButton:function(){
var button = new dijit.form.Button({onClick:function(){
removetrack();
testDataGrid.filter({status:"COMPLETED"});
}},"testButton1");
},
removetrack:function(){
//some logic
}
});
var customObj=new CustomClass();
customObj.createCustomButton();
I need removetrack()
method to be called when I click on the Button created.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 dojo.hitch();
Use dojo.hitch();
如果您需要紧急修复,我无法采取更好的方法,
希望有人能给您更好的选择。
I cannot manage to do better way, in case you need urgent fix
Hope someone can give you better option.