【问题标题】:how to get the id in extjs newly opened browser如何在extjs新打开的浏览器中获取id
【发布时间】:2016-01-22 14:50:05
【问题描述】:

我正在使用以下代码创建一个弹出窗口:

var window = Ext.create('Ext.window.Window',{
    title : headerMsg,
    width : 350,
    me:me,
    height : 250,
    layout : 'fit',
    plain : true,
    name : 'exportWin',
    id : 'exportWin' + (++eWin),
    buttonAlign : 'center',
    items : [{
        xtype : 'box',
        autoEl : {
            tag : 'iframe',
            src : url,
            id : eWin,
            name : 'ExportFrame',
            height : '100%',
            width : '100%',
            style : 'cursor:pointer;top:10px'
        }
    }
    ]
});
window.show();

一切正常,现在我需要在新打开的浏览器中获取 id。

我尝试了 window.id、self.id 和 this.id,但没有任何效果。 但 window.name 正在工作,它按预期警告“ExportFrame”,但 window.id 没有警告“eWin”变量,它警告为未定义 提前致谢!

【问题讨论】:

    标签: extjs extjs4 extjs3


    【解决方案1】:

    如果您想选择最近创建的Ext.window.Windowid 属性,您可以使用window.getId()

    如果您想选择子 iframe 的实际 id,您可以使用类似 Ext.dom.Query.select('iframe')[0].id.

    Working fiddle

    更多关于在this answer 中使用 ExtJS 浏览 DOM。

    【讨论】:

    • 嘿,谢谢...!!实际上,您正在记录 app.js 中的值,但我需要的是从新创建的框架中获取 ID,这意味着来自从 window.show() 创建的窗口;功能。我尝试了 self.id、window.id、this.id 但没有任何效果
    • 我明白了,你想从 iframe JS 代码中获取 ID。我想您必须将 ID 作为 iframe url 的一部分(或在加载 iframe 内容时以其他方式传递),因为<iframe> 标签是主浏览器窗口(ExtJS 工作的地方)的一部分,而 iframe 内容在其他窗口中执行..
    • 实际检查这个答案,我猜它是你要找的 - stackoverflow.com/a/7647123/2667065
    【解决方案2】:

    Ext.create 返回一个对象,因此您可以简单地使用 window.id 来访问该对象。

    要获取 iframe 的 ID,您可以使用:

    window.items.items[0].autoEl.id
    

    我用你的以下修改过的脚本对其进行了测试:

    var eWin = 1337;
    var Ywindow = Ext.create('Ext.window.Window',{
                title : 'dummy',
                width : 350,
                //me:me,
                height : 250,
                layout : 'fit',
                plain : true,
                name : 'exportWin',
                id : 'exportWin' + (++eWin),
                buttonAlign : 'center',
                items : [{
                    xtype : 'box',
                    autoEl : {
                        tag : 'iframe',
                        src : 'https://ccc.de',
                        id : eWin,
                        name : 'ExportFrame',
                        height : '100%',
                        width : '100%',
                        style : 'cursor:pointer;top:10px'
    }}]});
    Ywindow.show();
    console.log(Ywindow.items.items[0].autoEl.id);
    

    但正如您在代码中所写的那样:

    eWin or ++eWin. // in our case: 1338
    

    我更喜欢引用而不是 ID。 这让我从 MVVM 和 MVC 模式中获得了更多的力量。 https://docs.sencha.com/extjs/6.0/application_architecture/view_controllers.html

    顺便说一句,调用 var 窗口不是最佳选择 - window 是一个全局 JS 浏览器对象。

    因此我为演示目的创建了一个小提琴,这应该适用于 ExtJS 4+。

    https://fiddle.sencha.com/#fiddle/14do

    (看看控制台,你会发现两个id)

    【讨论】:

    • Hii 尝试了 window.id 但它没有显示 iframe 窗口 ID
    • 当然,window.id 显示 id : 'exportWin' + (++eWin)。 iframe id 是 eWin,对吧?
    • 您好,首先非常感谢您的快速回复。不,实际上,当我使用 window.id 时,它无论如何都显示未定义,但我期望看到的是 'exportWin' + (++eWin)(即 exportWin1、exportWin2、exportWin3 ...)而不是 ewin
    • iframe 的 id 为 eWin,面板的 id 为 'exportWin' + (++eWin)。看看小提琴,你可以找到一种方法来获取两个 Id。
    • 嘿,谢谢...!!实际上,您正在记录 app.js 中的值,但我需要的是从新创建的框架中获取 ID,这意味着来自从 window.show() 创建的窗口;功能。我尝试了 self.id、window.id 和 this.id,但没有任何效果
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-16
    • 1970-01-01
    • 2019-04-12
    • 2018-04-01
    • 1970-01-01
    相关资源
    最近更新 更多