Sencha Touch 使用Iframe 展示XML数据
其实sencha touch 展示XML数据有很多种方式,笔者在开发ST应用的时候会结合cordova或者phoneGap来开发,因此使用cordova的inappbrower或者themeablebrowser也能够展示XML数据,而且效果更好。但是因为客户的独特需求,上面两种方式并不能实现我的目标,因此,我改用了iframe,但是实际上不推荐使用iframe。
废话不多说上代码。
launch: function() {
Ext.define('I', {
extend: 'Ext.Component',
xtype: 'iframecmp',
config: {
url : null
},
initialize: function() {
console.log("Main");
var me = this;
me.callParent();
me.iframe = this.element.createChild({
tag: 'iframe',
src: this.getUrl(),
style: 'width: 500px; height: 2000px; align:middle;'
});
me.relayEvents(me.iframe, '*');
}
});
Ext.create("Ext.tab.Panel", {
extend: "I",
tabBarPosition: 'bottom',
fullscreen: true,
items: [
{
title: 'Sencha',
id: "main-frame",
name: "main-frame",
iconCls: 'action',
xtype: 'iframecmp',
url: 'http://192.168.1.204:7007/UpLoad/Menu/20160304014539/ceshi1.xml',
style: '-webkit-overflow-scrolling:touch;width: 100%; height: 100%;scroll:true;overflow-y: scroll; ',
scroll: 'vertical'
},
{
title: 'Sencha',
id: "main-frame2",
name: "main-frame2",
iconCls: 'action',
// xtype: 'iframecmp',
// url: 'http://192.168.1.204:7007/UpLoad/Menu/20160304014539/ceshi1.xml',
// style: 'width: 100%; height: 100%;scroll:true',
// scroll: 'vertical'
xtype: 'container',
html: '<iframe src="http://192.168.1.204:7007/ShareHTML/H5.html?id=59a55c57-94a9-4feb-a12a-70ca11d7d9f6"></iframe>',
style: 'width: 100%; height: 100%; '
}
]
});
其中有几点建议,
第一就是在设置iframe宽度的时候最好使用屏幕宽度。
第二就是IOS端是需要简单配置的。如果使用cordova来编译项目的话,需要在cordova的config.xml配置文件上加上如下所示一段话。
这样的话IOS端才能够使用IFrame,否则是不成功的
本文介绍如何在Sencha Touch应用中利用Iframe展示XML数据,并提供了具体代码实例。文章探讨了Iframe的局限性及其在iOS平台上的配置方法。
1574

被折叠的 条评论
为什么被折叠?



