如何从 Ext.Dialog 中获取 return 值?
How to return value from Ext.Dialog?
如何从 Ext.Dialog 中获取 return 值?我认为这是一项非常频繁的任务,但我一直找不到合适的答案。
我在这里看到的两个问题是:1) 如何 return 来自另一个对话框的值,以及 2) 如何从已调用对话框的视图中等待该值。
至于第一个问题,突然想到的一件事是将值写入调用者视图的viewModel,但我不知道如何等待该值。
我准备了一个简单的示例,我需要在其中创建 'MyApp.view.main.MyView'
,但为此我需要知道用户选择的是 A1、A2、A3 还是 A4。
onBtnClick: function(){
//call Dialog
Ext.create('MyApp.view.main.MyDialog', {}).show();
//how to get value from dialog and wait for that here?
//then call another view
Ext.create('MyApp.view.main.MyView', {
type: type,
}).show();
},
Ext.define('MyApp.view.main.MyDialog', {
extend: 'Ext.Dialog',
items: [
{
xtype: 'button',
text: 'A1',
handler: function(){
this.up().close();
}
},
{
xtype: 'button',
text: 'A2',
handler: function(){
this.up().close();
}
},
{
xtype: 'button',
text: 'A3',
handler: function(){
this.up().close();
}
},
{
xtype: 'button',
text: 'A4',
handler: function(){
this.up().close();
}
}
],
});
您可以使用自定义事件:
Ext.define('MyApp.view.main.MyDialog', {
extend: 'Ext.Dialog',
items: [{
xtype: 'button',
text: 'A1',
handler: function () {
this.up('dialog').fireEvent('dialogbuttonclick', 'A1');
this.up().close();
}
}, {
xtype: 'button',
text: 'A2',
handler: function () {
this.up('dialog').fireEvent('dialogbuttonclick', 'A2');
this.up().close();
}
}, {
xtype: 'button',
text: 'A3',
handler: function () {
this.up('dialog').fireEvent('dialogbuttonclick', 'A3');
this.up().close();
}
}, {
xtype: 'button',
text: 'A4',
handler: function (btn) {
this.up('dialog').fireEvent('dialogbuttonclick', 'A4');
this.up().close();
}
}],
});
Ext.create('MyApp.view.main.MyDialog', {
listeners: {
'dialogbuttonclick': function (buttonId) {
console.log(info.buttonId);
/*Ext.create('MyApp.view.main.MyView', {
type: buttonId,
}).show();*/
},
}
}).show();
如何从 Ext.Dialog 中获取 return 值?我认为这是一项非常频繁的任务,但我一直找不到合适的答案。
我在这里看到的两个问题是:1) 如何 return 来自另一个对话框的值,以及 2) 如何从已调用对话框的视图中等待该值。
至于第一个问题,突然想到的一件事是将值写入调用者视图的viewModel,但我不知道如何等待该值。
我准备了一个简单的示例,我需要在其中创建 'MyApp.view.main.MyView'
,但为此我需要知道用户选择的是 A1、A2、A3 还是 A4。
onBtnClick: function(){
//call Dialog
Ext.create('MyApp.view.main.MyDialog', {}).show();
//how to get value from dialog and wait for that here?
//then call another view
Ext.create('MyApp.view.main.MyView', {
type: type,
}).show();
},
Ext.define('MyApp.view.main.MyDialog', {
extend: 'Ext.Dialog',
items: [
{
xtype: 'button',
text: 'A1',
handler: function(){
this.up().close();
}
},
{
xtype: 'button',
text: 'A2',
handler: function(){
this.up().close();
}
},
{
xtype: 'button',
text: 'A3',
handler: function(){
this.up().close();
}
},
{
xtype: 'button',
text: 'A4',
handler: function(){
this.up().close();
}
}
],
});
您可以使用自定义事件:
Ext.define('MyApp.view.main.MyDialog', {
extend: 'Ext.Dialog',
items: [{
xtype: 'button',
text: 'A1',
handler: function () {
this.up('dialog').fireEvent('dialogbuttonclick', 'A1');
this.up().close();
}
}, {
xtype: 'button',
text: 'A2',
handler: function () {
this.up('dialog').fireEvent('dialogbuttonclick', 'A2');
this.up().close();
}
}, {
xtype: 'button',
text: 'A3',
handler: function () {
this.up('dialog').fireEvent('dialogbuttonclick', 'A3');
this.up().close();
}
}, {
xtype: 'button',
text: 'A4',
handler: function (btn) {
this.up('dialog').fireEvent('dialogbuttonclick', 'A4');
this.up().close();
}
}],
});
Ext.create('MyApp.view.main.MyDialog', {
listeners: {
'dialogbuttonclick': function (buttonId) {
console.log(info.buttonId);
/*Ext.create('MyApp.view.main.MyView', {
type: buttonId,
}).show();*/
},
}
}).show();