javascript 来自 URL 的 ExtJs4 加载面板
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7495293/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ExtJs4 load panel from URL
提问by Wisu Suntoyo
In ExtJs 3x this code
在 ExtJs 3x 中,此代码
Ext.getCmp('specific_panel_id').load({
url:'url_containing_scripts.htm',
scripts:true,
params:{
something:else
}
});
works for loading content from URL into a specific panel...
适用于将 URL 中的内容加载到特定面板中...
However it does not work in ExtJs 4.x.
但是它在 ExtJs 4.x 中不起作用。
回答by nonofce
This also work:
这也有效:
Ext.define('EI.view.Viewport',{
extend: 'Ext.container.Viewport',
alias: 'widget.principal',
layout: {
type: 'vbox',
align: 'center',
pack: 'center'
},
items:[
{
xtype: 'panel',
title: 'Mi Documentacion',
width: 800,
height: 600,
border: false,
autoScroll: true,
loader: {
autoLoad:true,
url :'http://localhost/docs/'
}
}
]
});
回答by suknic
The load method is gone from the Ext.panel.Panel in ExtJs4. As a workaround you could try to load your panel content with a regular Ext.Ajax.request and set these as items to your panel.
加载方法从 ExtJs4 中的 Ext.panel.Panel 中消失了。作为一种解决方法,您可以尝试使用常规 Ext.Ajax.request 加载面板内容,并将它们设置为面板的项目。
Example:
例子:
var itemsConfig;
Ext.Ajax.request({
url : 'url_containing_scripts.htm',
callback : function(options, success, response) {
itemsConfig = Ext.decode(response.text);
}
});
Ext.getCmp('specific_panel_id').add(itemsConfig);
Where url_containing_scripts.htm should have the items you want on your panel in JSON format.
url_ contains_scripts.htm 应该在面板上以 JSON 格式包含您想要的项目。
In the same way you can load the whole panel with all inital configuration settings you need.
以同样的方式,您可以使用您需要的所有初始配置设置加载整个面板。
回答by Wisu Suntoyo
Solved it with the following code:
用以下代码解决了它:
dynamicPanel = new Ext.Component({
loader: {
url: 'url_containing_scripts.htm',
renderer: 'html',
autoLoad: true,
scripts: true
}
});
Ext.getCmp('specific_panel_id').add(dynamicPanel);