sencha-touch-2 - 将外部 URL 加载到选项卡面板中?

标签 sencha-touch-2

我有一个简单的应用程序,可以加载我想要的托管网页 显示在单独的选项卡面板中。最干净的方法是什么? 选项卡可以在用户单击每个选项卡时加载,也可以一次性加载所有选项卡 在应用程序启动时。 Sencha Touch 没有办法简单地将 html: 值设置为 URL。我可以为每个选项卡添加一些页面加载事件吗?

[更新]

我添加了在initialize:方法中进行Ajax调用的建议,使用本地html文件进行测试。但是,所有选项卡都会显示第一个要完成的 Ajax 结果。

此代码现已完全正常运行。我忘记了:this.callParent(arguments);

我把例子放在SenchaFiddle上前两个选项卡不会加载,因为 ajax 调用失败,但最后两个 ComponentQuery 可以工作。


以下是屏幕外观的一个想法:

enter image description here

enter image description here

这是基本 View :

Ext.define('SenchaFiddle.view.MainView', {
    extend: 'Ext.tab.Panel',

    config: {
        tabBarPosition:'bottom',
        layout: {
            type: 'card',
            animation: {
                duration: 300,
                easing: 'ease-in-out',
                type: 'slide',
                direction: 'left'
            }
        },
        fullscreen: true,

        items: [
            {
                title: 'Top Stories',
                iconCls: 'info',
                xtype: 'panel',
                items: [
                    {
                        title: 'Top Stories',
                        xtype: 'toolbar',
                        docked: 'top'
                    },
                    {
                        id: 'image-tab',
                        html: 'Loading top stories url...'
                    }
                ]
            },
            {
                title: 'Entertainment',
                iconCls: 'action',
                items: [
                    {
                        title: 'Entertainment',
                        xtype: 'toolbar',
                        docked: 'top'
                    },
                    {
                        id: 'news-tab',
                        html: 'Loading entertainment url...'
                    }
                ]
            },
            {
                id: 'tab3',
                title: 'Sports',
                iconCls: 'user'
            },
            {
                id: 'tab4',
                title: 'Science',
                iconCls: 'star'
            }
        ]
    },
    initialize: function() {
        console.log("View initialized");
        Ext.Ajax.request({
            url: 'bar.html', // you must have access to the server
            method: 'GET',
            callback: function(options, success, response) {
                console.log(response.responseText);
                Ext.ComponentQuery.query('#image-tab')[0].setHtml(response.responseText);
            }
        });

        Ext.Ajax.request({
            url: 'foo.html', // you must have access to the server
            method: 'GET',
            callback: function(options, success, response) {
                console.log(response.responseText);
                Ext.ComponentQuery.query('#news-tab')[0].setHtml(response.responseText);
            }
        });
        Ext.ComponentQuery.query('#tab3')[0].setHtml("boom");
        Ext.ComponentQuery.query('#tab4')[0].setHtml("bang");

        this.callParent(arguments);  // Don't forget this!
    }
});

foo.html

<p style="color: #00f;">
    foo
</p>

bar.html

<p style="color: #0f0;">
    bar
</p>

最佳答案

尝试将其添加到您的 View 中(未测试):

Ext.Ajax.request({
    url: 'http://www.urlForTopStories', // you must have access to the server
    method: 'GET',
    callback: function(options, success, response) {
        Ext.ComponentQuery.query('#image-tab')[0].setHtml(response.responseText);
    }
});  

如果您有 .htaccess 文件中的 urlForTopStories,请将其发送到您的服务器:

Header set Access-Control-Allow-Origin *
Header set Access-Control-Allow-Headers x-requested-with

如果您没有使用 Apache,请查看此 CORS资源以获取更多帮助。

关于sencha-touch-2 - 将外部 URL 加载到选项卡面板中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10535721/

相关文章:

sencha-touch-2 - 为什么 Sencha Touch cmd 中没有 View 构建

javascript - 在 Sencha Touch 2 中的 itemswipe 上显示复选框?

android - Sencha 应用程序在 IOS 和 Android 上太慢

sencha-touch-2 - 在另一个组件上管理一个组件上的点击事件

sencha-touch-2 - 不能在商店或 View 中使用 getApplication()

javascript - Sencha Touch 2 + PhoneGap + iPad : Video with base64 encoded data: "The Operation could not be completed"

sencha-touch-2 - sencha touch 2 应用程序的警告消息

ios - sencha touch microloader 在 iOS 中不工作

audio - 添加到主屏幕后无法播放音频-Sencha Touch

javascript - 在创建项目时获取 Ext.Container 的一些静态属性