Extjs Ext.Msg.confirm回调未创建闭包
例如:Extjs Ext.Msg.confirm回调未创建闭包,extjs,callback,sencha-touch,closures,sencha-touch-2,Extjs,Callback,Sencha Touch,Closures,Sencha Touch 2,例如: disclose: function (list, record, node, index, event) { Ext.Msg.confirm('Delete Requirement', 'Are you sure?', function (id, value) { if (id === 'yes') { console.log('confirmed'); // no access to list, record,
disclose: function (list, record, node, index, event) {
Ext.Msg.confirm('Delete Requirement', 'Are you sure?', function (id, value) {
if (id === 'yes') {
console.log('confirmed');
// no access to list, record, node, ... here, why?
}
}, this);
event.stopEvent();
}
如何在确认消息处理程序中访问列表和记录变量?我找到了一个解决方案:
disclose: function (list, record, node, index, event) {
(new Ext.MessageBox).show({
title: 'Delete Requirement',
message: 'Are you sure?',
list: list,
record: record,
buttons: Ext.MessageBox.YESNO,
promptConfig: false,
fn: function (id, value, opt) {
if (id === 'yes') {
opt.record.destroy();
}
}
});
event.stopEvent();
}
我找到了一个解决方案:
disclose: function (list, record, node, index, event) {
(new Ext.MessageBox).show({
title: 'Delete Requirement',
message: 'Are you sure?',
list: list,
record: record,
buttons: Ext.MessageBox.YESNO,
promptConfig: false,
fn: function (id, value, opt) {
if (id === 'yes') {
opt.record.destroy();
}
}
});
event.stopEvent();
}
您确实可以访问
列表
和记录
。你看到了什么使它看起来像你没有看到的?console.log(列表)是什么;然后返回?您确定绑定到“披露”的事件实际提供(列表、记录)等参数吗?当然,披露确实包括列表、记录等参数。但是在回调中它们是未定义的,Web Inspector没有在本地范围中显示它们。@非常奇怪。看一看,这似乎与您正在做的事情相同,但回调可以访问列表
,记录
,等等。很好。您确实可以访问那里的列表
和记录
。你看到了什么使它看起来像你没有看到的?console.log(列表)是什么;然后返回?您确定绑定到“披露”的事件实际提供(列表、记录)等参数吗?当然,披露确实包括列表、记录等参数。但是在回调中它们是未定义的,Web Inspector没有在本地范围中显示它们。@非常奇怪。看一看,这似乎与您正在做的事情相同,但回调可以访问列表
,记录
,等等。很好。这很有效!我想知道为什么?为什么闭包看不到父函数参数,但会看到它的局部变量?这些基本上是一样的吗?我不确定,但我认为这是因为函数的变量实际上是参数[0]…参数[n]
。所以嵌套回调参数中的参数已经不同了。这很有效!我想知道为什么?为什么闭包看不到父函数参数,但会看到它的局部变量?这些基本上是一样的吗?我不确定,但我认为这是因为函数的变量实际上是参数[0]…参数[n]
。因此,内部嵌套回调参数
已经不同了。