首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Sencha Touch:按钮

Sencha Touch:按钮
EN

Stack Overflow用户
提问于 2012-04-25 11:16:23
回答 3查看 4.6K关注 0票数 0

我正在尝试使用Sencha Touch 2在弹出窗口中实现按钮。这些按钮是如何工作的?我想要一个按钮关闭窗口,另一个按钮调用doSomething函数。

代码语言:javascript
复制
function foo(){
    Ext.Viewport.add({
        xtype: 'panel',
        scrollable: true,
        centered: true,
        width: 400,
        height: 300,
        items:[
            {
                docked: 'bottom',
                xtype: 'titlebar',
                items:[
                    {
                        xtype: 'button',
                        ui: 'normal',
                        text: 'Do Something',
                        go: 'testsecond'
                    },  
                    {
                        xtype: 'button',
                        ui: 'normal',
                        text: 'Close',
                        go: 'testsecond',               
                    },                  
                ]
            },
        ]
    });//Ext.Viewport.add
}

function doSomething() {
    console.log('hi');
}
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2012-04-25 16:37:38

只需向按钮添加一个处理程序,如下所示

代码语言:javascript
复制
{
    xtype: 'button',
    ui: 'normal',
    text: 'Close',
    go: 'testsecond',
    handler:doSomething               
}

代码语言:javascript
复制
{
    xtype: 'button',
    ui: 'normal',
    text: 'Close',
    go: 'testsecond',
    handler:function(){
        //do something.
    }               
}
票数 1
EN

Stack Overflow用户

发布于 2012-04-25 19:27:32

我想,你需要一些与Sencha Touch中的overlay类似的东西。

因为你要弹出窗口,所以你应该让这个面板成为浮动的。

下面是它们的工作原理:

代码语言:javascript
复制
Ext.Loader.setConfig({
    enabled: true
});

Ext.application({
    name: 'FloatingPanelWindow',

    launch: function() {
        overlay = Ext.Viewport.add({
            xtype: 'panel',
            scrollable: true,
            modal: true,                  // to make it floating
            hideOnMaskTap: true,          // close the window by clicking on mask outside popup window
            centered: true,
            width: 400,
            height: 300,
            items:[
                {
                    docked: 'bottom',
                    xtype: 'titlebar',
                    items:[
                        {
                            xtype: 'button',
                            ui: 'normal',
                            text: 'Do Something',
                            listeners : {
                                tap : function() {
                                    overlay.hide(); // to close this popup window.
                                    Ext.Msg.alert("Clicked on DoSomething"); //callDoSomethingMethod(); // perform your task here.                               
                                }
                            }
                        },  
                        {
                            xtype: 'button',
                            ui: 'normal',
                            text: 'Close',
                            listeners : {
                                tap : function() {
                                    overlay.hide();
                                }
                            }              
                        },                  
                    ]
                        },
                    ]
     });//Ext.Viewport.add
    }
 }); 

这是您将获得的示例输出。

票数 1
EN

Stack Overflow用户

发布于 2012-04-25 18:01:52

这里很简单

代码语言:javascript
复制
                {
                    xtype: 'button',
                    ui: 'normal',
                    text: 'Do Something',
                    go: 'testsecond',
                    handler:function(){
                    //do something.
                    }
                },  
                {
                    xtype: 'button',
                    ui: 'normal',
                    text: 'Close',
                    go: 'testsecond',
                    handler:function(){
                      //popup_window.hide();
                    }               
                }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10308881

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档