我使用此代码在论坛上发现没有错误在4.0.2a和现在4.0.7给我错误 f是null 所以我检查了firebug并发现
getIframe: function() {
return this.getTargetEl().child('iframe');
},
this.getTargetEl()。child('iframe')返回null
所以任何想法为什么会发生4.0.7?
Ext.define('Ext.panel.iframePanel', {
extend : 'Ext.panel.Panel',
alias : 'widget.iframePanel',
src : 'about:blank',
loadingText : 'Loading ...',
loadingConfig : null,
renderTpl: [
'<div class="{baseCls}-body<tpl if="bodyCls"> {bodyCls}</tpl><tpl if="frame"> {baseCls}-body-framed</tpl><tpl if="ui"> {baseCls}-body-{ui}</tpl>"<tpl if="bodyStyle"> style="{bodyStyle}"</tpl>>',
'<iframe src="{src}" width="100%" height="100%" frameborder="0"></iframe>',
'</div>'
],
initRenderData: function() {
return Ext.applyIf(this.callParent(), {
bodyStyle: this.initBodyStyles(),
bodyCls: this.initBodyCls(),
src: this.getSource()
});
},
initComponent: function() {
this.callParent(arguments);
this.on('afterrender', this.onAfterRender, this, {});
},
/**
* Gets the iframe element
*/
getIframe: function() {
return this.getTargetEl().child('iframe');
},
getSource: function() {
return this.src;
},
setSource: function(src, loadingText) {
this.src = src;
var f = this.getIframe();
if (loadingText || this.loadingText) {
this.body.mask(loadingText || this.loadingText);
}
f.dom.src = src;
},
resetUrl: function() {
var f = this.getIframe();
f.dom.src = this.src;
},
onAfterRender: function() {
var f = this.getIframe();
f.on('load', this.onIframeLoaded, this, {});
},
onIframeLoaded: function() {
if (this.loadingText) {
this.body.unmask();
}
}
});
var printpanel = Ext.create('Ext.panel.Panel', {
title : 'Print',
width : 800,
height : 300,
renderTo : Ext.getBody(),
bodyPadding : 5,
layout : 'fit',
items: Ext.widget('iframePanel', {
border : false,
src : '',
itemId : 'ds_print_panel'
}),
tbar: ['->',{
text : 'Test',
listeners: {
click: function(){
printpanel.down('#ds_print_panel').setSource("http://www.rockstown.com/node/4");
}
}
}]
});
答案 0 :(得分:3)
我在这里发现了一些错误。
child('iframe')
返回null,因为在Ext4中它选择了一个直接子节点(与Ext3相反)。您应该使用down('iframe')
代替body
未在iframePanel
中定义,请使用getTargetEl()
printpanel.down('#ds_print_panel')
也不起作用,你可以使用eg。 this.findParentByType('panel')
以下是工作示例:http://jsfiddle.net/Cu9DZ/3/