gpt4 book ai didi

extjs4.1 - Extjs this.up(...).down(...) 为空

转载 作者:行者123 更新时间:2023-12-02 21:33:56 26 4
gpt4 key购买 nike

当我按下保存按钮时,它工作正常。但是当我在此字段上按 Enter 时,我遇到一些问题,错误消息是 this.up(...).down(...) 为空。下面给出了我的窗口。我只是想,当您在文本框中按 Enter 时,它会像您单击了按钮一样。

有人可以帮忙吗?

Ext.define('${pkgName}.v01i002001.SV01I00200201' , {
extend : 'Ext.window.Window',
alias : 'widget.sv01i00200201',
id : 'sv01i00200201',
title : 'MANUFACTURE :: SV01I00200201',
minimizable : false,
maximizable : false,
autoShow : true,
resizable : false,
border : false,
modal : true,
padding : '0 5 0 5',
icon : "${resource(dir: 'images', file: 'APP01003.png')}",
layout : {
type: 'vbox',
align: 'stretch'
},
initComponent : function () {
var me = this;
var required = '<span style="color:red;font-weight:bold" data-qtip="Required">*</span>';
this.items = [
{
xtype : 'form',
bodyStyle : {
padding : '10px',
border : true
},
tbar: Ext.create('Ext.ux.StatusBar', {
id : 'win-statusbar-sv01i00200201',
topBorder :true,
text :'Status',
defaultIconCls : 'info',
defaultText : 'Status'
}),
items : [{
xtype : 'textfield',
fieldLabel : 'Id',
name : 'id',
width : 265,
anchor : '95%',
emptyText : 'Not need...',
readOnly : true
},{
xtype : 'textfield',
fieldLabel : 'Manufac. Name',
emptyText : 'Write Manufacturer name',
allowBlank : false,
name : 'name',
width : 265,
anchor : '95%',
listeners: {
specialkey : function(field, e){
if (e.getKey() == e.ENTER || e.getKey()==e.TAB) {
//Ext.get('save-sv01i00200201').dom.click(); //it work
// this.up().up().down('button[action=save]').fireEvent('click'); //TypeError: button.up is not a function
// this.up('sv01i00200201').down('button[action=save]').fireEvent('click');//TypeError: button.up is not a function
// this.up('window').down('button[action=save]').fireEvent('click'); //TypeError: button.up is not a function
}
}
}
}]
}]
this.buttons = [
{
text : 'Save',
icon : "${resource(dir: 'images', file: 'SAV01004.png')}",
id : 'save-sv01i00200201',
action : 'save'
},{
text : 'Close',
icon : "${resource(dir: 'images', file: 'CLS01001.png')}",
scope : this,
handler : function(button){
var win = button.up('window');
win.close();
}
}]
me.callParent(arguments);
}
});

下面给出了我的 Controller

Ext.define('${pkgName}.C01I002001', {
extend : 'Ext.app.Controller',
requires: [],

views:[
'V01I001000',
'v01i002001.SV01I00200100',
'v01i002001.SV01I00200101',
'v01i001001.SV01I00200104',
'v01i001001.SV01I00200106',
'v01i002001.SV01I00200201',
'v01i002001.SV01I00200301'
],
refs : [{
ref : 'v01i002001',
selector: 'window'
}],
init: function() {
manuStore = Ext.data.StoreManager.get('S01I002001');
var me = this;
me.category = undefined;
me.control({
'sv01i00200201 button[action=save]': {
click : this.manufacturerSave
}
});
},
manufacturerSave : function(button){
win = button.up('window'),
form = win.down('form'),
record = form.getRecord(),
values = form.getValues();

if(form.getForm().isValid()){

var manufacturer = Ext.create('${appName}.model.M01I002001',{
name:values.name
});

manufacturer.save({
scope:this,
success:function(records, operation){
var text = operation.response.responseText,
json = Ext.decode(text);
form.loadRecord(records);
controller000.statusbar('sv01i00200201', json.message, 'saveInfo', 'activecaption');
manuStore.load();
var win = Ext.getCmp('sv01i00200201');
controller000.closeWindow(win);
},

failure:function(model, operation){
controller000.statusbar('sv01i00200201', operation.error, 'warnInfo', 'red');
}
});
}else{
controller000.statusbar('sv01i00200201', 'Necessary Field Required', 'warnInfo', 'red');

}
}
});

最佳答案

this.up() 仅通过一层针对字段的直接父级(表单面板)向上冒泡。请尝试以下选项之一:

this.up().up().down('button[action=save]').fireEvent('click');
this.up('window').down('button[action=save]').fireEvent('click');
this.up('#sv01i00200201').down('button[action=save]').fireEvent('click');

看看 documentation ;)

<小时/>

第 2 部分:“button.up 不是函数”

我想我明白了,您必须手动将按钮作为参数传递给 fireEvent 函数:

var button = this.up('window').down('button[action=save]');
button.fireEvent('click', button);

关于extjs4.1 - Extjs this.up(...).down(...) 为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15446576/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com