Render Extjs elements into other frame

久未见 提交于 2019-12-25 01:55:49

问题


I want to render Ext elements in an iframe.

In the page that is loaded into the iframe, I have a div element:

<div id="panel"></div>

When the iframe is loaded, I want to render an Ext panel into this div element.

So the page loaded into the iframe got a function which is executed on load:

console.log(parent.Ext.get("panel"));
console.log(document.getElementById("panel"));
console.log(new parent.Ext.dom.Element(document.getElementById("panel")));
parent.Ext.create('Ext.Panel',{
    layout : 'fit',
    height : 200,
    width : 600,
    autoScroll: false,
    renderTo : new parent.Ext.dom.Element(document.getElementById("panel"))
});

The console messages are as follows:

null VM14143:10
<div id=​"panel">​…​</div>​ VM14143:11
D {el: D, dom: div#panel, id: "panel", $cache: Object, self: function…} VM14143:12
TypeError: Cannot read property 'dom' of null

The TypeError is occuring no matter which of the three console.logs I put into renderTo: renderTo: parent.Ext.get("panel") or renderTo: document.getElementById("panel") or renderTo: new parent.Ext.dom.Element(document.getElementById("panel")), but it does not occur when I remove the renderTo line completely.

Now, how can I render a panel into my div?


回答1:


What you are trying to do is wrong. Because when you do parent.Ext, it will execute in parent scope than in current scope(which is iframe) So what you need to do is, have ExtJS library loaded in the iframe as well, and execute the code.



来源:https://stackoverflow.com/questions/22298253/render-extjs-elements-into-other-frame

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!