如何在面板或容器sencha touch 2.3中加载外部html文件

时间:2013-10-21 07:02:03

标签: extjs

我正在尝试使用Sencha touch为iOS和Android开发应用程序,我想创建一个面板或容器,用于加载放置在同一文件夹中的外部HTML。

因为我们在Android中的phonegap应用程序或iOS中的UIWebView中使用webview。

2 个答案:

答案 0 :(得分:4)

Ext.define('MyApp.view.MyPanel', {
extend: 'Ext.Panel',
config: {
    id: 'MyPanel',
    itemId: 'MyPanel',
    scrollable: true,
    listeners: [
        {
            fn: 'onMyPanelActivate',
            event: 'activate'
        }
    ]
},    onMyPanelActivate: function(newActiveItem, container, oldActiveItem, eOpts) {
    Ext.Ajax.request({
        //local path of your html file
        url: 'html/index.html',
        success : function(response) {
           Ext.getCmp('MyPanel').setHtml(response.responseText);
        },
        failure : function(response) {  
            var text = response.responseText;
            Ext.Msg.alert('Error', text, Ext.emptyFn);            }
    });
}});

答案 1 :(得分:0)

//Created this Panel Extender, that suited me better:

Ext.define('Pricing.controller.HtmlPanelExtender', {
    extend: 'Ext.Panel',
    alias: 'widget.htmlPanelExtender',
    autoScroll: true,
    constructor: function (config) {
        this.superclass.constructor.apply(this, arguments);
        this.loaded = false;
        this.load = function () {
            if (!this.loaded && this.url && (this.url.length > 0)) {
                Ext.Ajax.request({
                    disableCaching: false,
                    url: this.url,
                    method: "GET",
                    panel: this,
                    success: function (response, request) {
                        request.panel.update(response.responseText);
                        request.panel.loaded = true;
                    }
                });
            }
        };
        this.on('show', this.load);
        if (this.autoLoad) {
            this.load();
        }
    },
    url: null
});



// use it like this

items: [{
    id: 'abc',
    xtype: 'htmlPanelExtender',
    scroll: 'vertical',
    border: 0,
    autoLoad: true,
    url: 'templates/adminhome.html'
}]