當一個專案被動態地添加到已創建的組件中時,如果該專案中存在錯誤,應用程式就會崩潰。
當專案沒有被創建時,這個問題并不存在。
。
Ext.define('Test', {
extend: 'Ext.panel.Panel',
initComponent: function () {
//span>出錯。
// this.callParent();/span>
}
});
Ext.create('Ext.panel.Panel', {
renderTo: Ext.getBody()。
width: 400。
高度。300,
title: '應用'。
layout: {
type: 'vbox'。
align: 'center',
},
defaults: {
margin: 10,
},
items: [{
xtype: 'button',
iconCls: 'x-fa fa-cog',
handler: function (btn) {
let mainPanel = btn.up('panel'/span>)。
item = Ext.create('Test')。
//bug.
mainPanel.add(item)。
},
}],
});
uj5u.com熱心網友回復:
很奇怪的問題,因為你正試圖找出開發者在運行時是否做錯了什么。
但不管怎樣--這里有一個解決你問題的方法:
handler: function (btn) {
let mainPanel = btn.up('panel'/span>)。
item = Ext.create('Test')。
//bug測驗。
if(Ext.isDefined(item) && Ext. isObject(item.layout) {
mainPanel.add(item)。
} else {
console.error(item.id ' could not be added because of an error I made. ')
}
},
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/310482.html
標籤:
