我不断收到此错误,无法找到控制器
// 저장
onSaveClick: function() {
debugger;
var me = this;
var myForm = me.getView().down('#myForm').getForm();
//var recipe_id = myForm.findField('recipe_id').getValue();
var equip_pm_plan_id = myForm.findField('equip_pm_plan_id').getValue();
var equip_code = myForm.findField('equip_code').getValue();
var att_type = myForm.findField('att_type').getValue();
var fileName = myForm.findField('fileupload').getValue();
var setCrud = "I";
if(fileName.length == 0){
toastr.warning("업로드할 첨부파일이 존재하지 않습니다");
return false;
}
var attFile = myForm.findField('attFile').getValue();
if(attFile.length > 0){
setCrud = "U"
}
myForm.findField('crud').setValue(setCrud);
myForm.findField('att_doc_no').setValue(equip_pm_plan_id);
myForm.findField('att_doc_no').setValue(equip_code);
var msgConfirm = me.getView().저장하시겠습니까;
var msgResult = me.getView().파일업로드가완료되었습니다;
Ext.Msg.confirm(me.getView().확인, msgConfirm, function(btn){
if (btn == 'yes') {
myForm.submit({
url: '../saveAttachFile',
waitTitle: me.getView().연결중,
waitMsg: me.getView().데이터수신중,
success: function(form, action){
//me.myStore.reload();
toastr.info(msgResult);
//var recipe_id = myForm.findField('recipe_id').getValue();
var equip_pm_plan_id = myForm.findField('equip_pm_plan_id').getValue();
var equip_code = myForm.findField('equip_code').getValue();
var parent_store = myForm.findField('parent_store').getValue();
Ext.getCmp('equipChkEdit').controller.getAttachFile(equip_pm_plan_id, equip_code);
//me.getView().close();
me.onRefresh();
},
failure: function(form, action) {
var message = Ext.ux.submitFailure(form, action);
Ext.Msg.show({title: action.failureType + '-side failure', msg: message, icon: Ext.Msg.ERROR, buttons: Ext.Msg.OK});
}
});
}
});
},
这是给出错误的函数。
Ext.getCmp('equipChkEdit').controller.getAttachFile(equip_pm_plan_id, equip_code);
这是返回错误的部分。
但是这个错误没有意义,因为我有一个名为EquipChkEdit.js的单独的js文件以及名为equipChkEditController.js的控制器js文件
我的示例解决方案具有完全相同的结构和相同的语法
我已检查文件名和位置。它们位于同一个文件夹中,并且名称匹配,因为它们的拼写都是准确的。
我尝试了 Ext.getCmp('equipChkEditController') 但意识到这实际上是错误的,因为 .controller 部分是控制器的组成部分。
Ext.define('WithGMP.view.equipmaint.equipChkEdit', {
extend: 'Ext.window.Window',
requires: [
'Ext.grid.column.Action',
'Ext.grid.filters.Filters',
'Ext.tab.Tab',
'WithGMP.store.ComboStore'
],
xtype: 'form-equipchkedit-window',
controller: 'equipmaint.equipchkedit',
reference: 'equipChkEdit',
title: '설비 점검결과 등록',
width: 800,
height: 350,
minWidth: 300,
minHeight: 300,
layout: 'fit',
resizable: true,
border: true,
modal: true,
这是 EquipmentChkEdit.js 文件,它在其中定义其控制器,这是定义它的正确方法,因为这是所有示例解决方案定义其控制器的方式。
//첨부파일 조회
getAttachFile: function(equip_pm_plan_id, equip_code) {
var me = this;
var attachImageStore = Ext.create('WithGMP.store.recipe.attachImageStore');
attachImageStore.load({
params: {equip_pm_plan_id: equip_pm_plan_id, equip_code : equip_code},
callback : function(records, operation, success) {
if (!success) {
} else {
//attImagteBtn.Text = Convert.ToString(dt.Rows[0]["IMGCOUNT"]) + " 건";
//myForm.findField('attImagteBtn').setValue(records[0].data + " 건");
me.getView().down('#attFileBtn').setText(me.getView().첨부파일 + " " + records[0].data + " 건");
}
}
});
},
这是equipChkEditController.js,定义了函数getAttachFile,在给出错误的部分使用了该函数
定义和拼写正确
我不知道为什么
Ext.getCmp('equipChkEdit').controller.getAttachFile(equip_pm_plan_id, equip_code);
此行在执行时能够找到控制器。
总的来说,如果您能创建一个小提琴,这样其他人就可以看到这些组件如何协同工作,那就太好了。您正在尝试从其他窗口调用窗口控制器吗?
有6种可能的解决方案:
getCmp 文档:链接
您必须使用组件的 ID。通常我不建议使用 ID。主要原因是,您可能想打开多个窗口,并且 ID 必须是唯一的。
reference
或使用 up
和 down
。:const editWindow = me.lookupReference('equipChkEdit'),
upDownEdit = me.getView().up('someParent').down('aField');
equipChkAttachFileController.js
Ext.fireEvent('attachedfilechange', [equip_pm_plan_id, equip_code]);
equipChkEditController.js
listen: {
global: {
attachedfilechange: 'getAttachFile'
}
}
Ext.define('WithGMP.util.Attachments', {
singleton: true,
fileAttached: function(equip_pm_plan_id, equip_code) {
...do something
}
});
调用util函数
WithGMP.util.Attachments.fileAttached(equip_pm_plan_id, equip_code);
使用数据绑定。如果将数据绑定到父组件,则可以从两个不同的窗口访问它。为此,您必须使用parentViewModel 定义窗口。
最后但并非最不重要的一点是,您可能还没有创建视图
equipChkEdit
。