javascript - 为什么这个 extjs 代码在 extjs 4.0.7 中返回 null?

标签 javascript extjs extjs4

我使用了在论坛上找到的代码,在 4.0.2a 中没有错误,现在 4.0.7 给了我错误 f is null 所以我检查了 firebug 并发现了

getIframe: function() {
  return this.getTargetEl().child('iframe');
},

this.getTargetEl().child('iframe') 返回 null

那么知道为什么 4.0.7 会发生这种情况吗?

http://jsfiddle.net/Cu9DZ/

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");
                    }
                }
            }]          
});

最佳答案

我在这里发现了一些错误。

  1. 正如您所知,child('iframe') 返回 null,因为在 Ext4 中它选择单个直接子级(与 Ext3 相反)。您应该使用 down('iframe') 来代替
  2. bodyiframePanel 中未定义,请使用 getTargetEl() 代替
  3. printpanel.down('#ds_print_panel') 也不起作用,您可以使用例如。 this.findParentByType('面板')

这是工作示例:http://jsfiddle.net/Cu9DZ/3/

关于javascript - 为什么这个 extjs 代码在 extjs 4.0.7 中返回 null?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8832486/

相关文章:

javascript - 停止在后面的 div 中滚动

javascript - 使用部分 View 从多个位置引用相同的 js 文件

javascript - 一个 GET 请求在 Safari 中不起作用(授权问题)-Angular 6

javascript - 如何将事件监听器添加到对象数组

javascript - 如何在 Sencha Touch 应用程序中使用以前的过滤器获取总记录?

javascript - ExtJS - 堆积条形图

extjs - 访问相邻组件/字段的最佳方式

extjs4 - ext js4 到 sencha touch 转换器

javascript - 刷新本地存储后恢复下拉选择

javascript - ExtJs 4 上的 TreeNode 单击事件