我有代码:
win = desktop.createWindow({
id: 'admin-win',
title: 'Add administration users',
width: 740,
height: 480,
iconCls: 'icon-grid',
animCollapse: false,
constrainHeader: true,
xtype: 'form',
bodyPadding: 15,
url: 'save-form.php',
items: [{
xtype: 'textfield',
fieldLabel: 'Field',
name: 'theField'
}],
buttons: [{
text: 'Submit',
handler: function () {
var form = this.up('form').getForm();
if (form.isValid()) {
form.submit({
success: function (form, action) {
Ext.Msg.alert('Success', action.result.message);
},
failure: function (form, action) {
Ext.Msg.alert('Failed', action.result ? action.result.message : 'No response');
}
});
}
}
}]
});
按钮不起作用。它会产生错误 - this.up('form')未定义。如何在这样的代码中调用getForm()?
更新: 谢谢你真的快速回复! 我根据需要修改了代码,就是这样,它适用于桌面示例:
win = desktop.createWindow({
id: 'admin-win',
title: 'Add administration users',
width: 740,
iconCls: 'icon-grid',
animCollapse: false,
constrainHeader: true,
items: [{
xtype: 'form',
bodyPadding: 15,
url: 'save-form.php',
items: [{
xtype: 'textfield',
fieldLabel: 'Field',
name: 'theField'
}],
buttons: [{
text: 'Submit',
handler: function () {
var form = this.up('form').getForm();
if (form.isValid()) {
this.up().up().submit({
success: function (form, action) {
Ext.Msg.alert('Success', action.result.message);
},
failure: function (form, action) {
Ext.Msg.alert('Failed', action.result ? action.result.message : 'No response');
}
});
}
}
}]
}]
});
答案 0 :(得分:5)
正如我已经说过的,您的代码似乎有问题。您正在将Ext.form.Panel选项传递给Ext.window.Window(我假设这是因为您正在调用的方法的名称)。我正在为你写一个带窗口的例子。片刻。
准备就绪。看看:
Ext.create('Ext.window.Window', {
title: 'This is a Window with a Form',
height: 200,
width: 400,
layout: 'fit',
items: [{ // the form is an item of the window
id: 'admin-win',
title: 'Add administration users',
width: 740,
height: 480,
iconCls: 'icon-grid',
animCollapse: false,
constrainHeader: true,
xtype: 'form',
bodyPadding: 15,
url: 'save-form.php',
items: [{
xtype: 'textfield',
fieldLabel: 'Field',
name: 'theField',
allowBlank: false
}],
buttons: [{
text: 'Submit',
handler: function() {
var form = this.up('form').getForm();
if (form.isValid()) {
form.submit({
success: function(form, action) {
Ext.Msg.alert('Success', action.result.message);
},
failure: function(form, action) {
Ext.Msg.alert('Failed', action.result ? action.result.message : 'No response');
}
});
} else {
Ext.Msg.alert( "Error!", "Your form is invalid!" );
}
}
}]
}]
}).show();