2017-01-16 58 views
1

我已经创建了一个iFrame窗口,并且有单独的分机应用程序。如何访问iFrame的主要

Win = new Ext.IframeWindow({ 
         id: 'MyWinID', 
         modal: true, 
         resizable: true, 
         title: 'H1', 
         closable: true, 
         constrain : true, 
        }); 
    Win.width = (winWidth/100) * 90, 
    Win.height = (winHeight/100) * 90, 
    Win.show().center(); 

在调整大小时,我想访问放置在iFrame中的应用程序。

listeners :{ 
      resize : function(a,b,c){ 
       // How to access element of main at this point. I am trying this 
       var WinFrame = window.frames['MyWinID'] 
       } 
      } 

我主要的iFrame应用程序是

Ext.define('My.view.main.Main', { 
    extend: 'Ext.panel.Panel', 
    xtype: 'app-main', 

    requires: [ 
     'Ext.plugin.Viewport', 
     'Ext.tab.Panel', 
    ], 

    controller: 'main', 
    viewModel: 'main', 
    layout: 'border', 

    items: [{ 
     xtype: 'toolbar', 
     frame: true, 
     region: 'south', 
     items: [ some item] 
    }, 
    { 
     title: 'App', 
     itemId: 'selectionPanel', 
     region: 'west', 
     xtype: 'panel', 
     scroll: 'y', 
     frame: true, 
     items: [] 
    }, 
    { 
     xtype: 'panel',  
     region: 'center', 
     frame: true, 
     scrollable: true, 
     scroll: 'y',  
     itemId: 'abc', 
     reference: 'abc', 
     layout: { 
      //type: 'anchor', 
      type: 'vbox', 
      align: 'stretch' 
     }, 
     items: [] 
    }] 
}); 

能否请你建议如何实现这一目标。

回答

1

的Javascript基本规则:

“全局” 变量(例如Ext)在树可用window,反之亦然下,所以window.Ext.getCmp("MyWinID")Ext.getCmp("MyWinID")是相同的。对于帧

JavaScript规则:

window.frames[id]包含所选择的帧的window元件。

两者一起得到的回答你的问题,它可以在这个简单的例子来概括:

window.frames['MyAppFrame'].Ext.getCmp("MyTestContainer").add({ 
    xtype:'button', 
    handler:function(btn) { 
     btn.up('form').submit(); 
    } 
}); 
+0

window.Ext.getCmp(“MyWinID”)这一部分,我明白,我在我的监听使用,但是如何使用'Ext.getCmp(“MyTestContainer)',因为你可以在我的主窗口中看到我需要访问主窗口的一个项目。我能够访问窗口,但不能访问窗口中的任何项目 – David

+0

通过使用'window.frames ['MyID']'我得到一些html和div组件,并且在打开div之后,我将iframe作为标签获得。如何访问它 – David

+0

@David您可以进入Sencha小提琴a nd测试。小提琴在iframe中运行。 'window.frames [0] .Ext'从浏览器控制台为您提供小提琴的'Ext'对象。不知道你在代码中究竟做了什么不同... – Alexander