如何在Sencha触摸工具栏中链接按钮? [英] How to link buttons in toolbar in Sencha touch?

查看:127
本文介绍了如何在Sencha触摸工具栏中链接按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有多个按钮加载在按钮工具栏中,我需要这些按钮才能进入不同的链接。但是,我一直没能弄清楚。下面是我试图做的,但它不工作。

I have multiple buttons loading up in the button toolbar I need those buttons to go to different links. However, I have not been able to figure it out. Below is what I tried to do but it does not work.

        //Below are three buttons that need to go to three different links 
    var buttonsGroup1 = new Ext.Button({
    text: 'MESSAGES',
    handler: tapHandler
    });

    var buttonsGroup2 = new Ext.Button({
    text: 'HOLDS',
    handler: tap2Handler
    });

    var buttonsGroup3 = new Ext.Button({
    text: 'FINANCIALS',
    handler: tapHandler
    });

    //Click on the button and it goes to these links 
    var tapHandler = function (btn, evt) {
        window.location = 'index.html';
    };

    var tap2Handler = function (btn, evt) {
        window.location = 'redirect.php';
    };

    //Combine all the variables above and some other stuff and then add it to docked items very object oriented =)
    var dockedItems = [
    {
        xtype: 'toolbar',
        title: 'Student Portal',
        ui: 'light',
        dock: 'top',
        items: buttonsSpecTop,
        defaults: { handler: tapHandler }
    },  
    {
        xtype: 'toolbar',
        ui: 'dark',
        items: [buttonsGroup1, buttonsGroup2, buttonsGroup3], //This is where I load up all the buttons 
        dock: 'bottom',
        layout:{
        pack: 'center'
        },
        defaults: [handler: tapHandler, handler: tap2Handler] //This is the handler for the links

    }];


推荐答案

对于每个按钮配置,添加一个额外的配置参数说actionUrl这样:

For each button config, add one extra config param say actionUrl this way:

{
    xtype: 'toolbar',
    actionUrl : 'http://www.google.com',
    title: 'Student Portal',
    ui: 'light',
    dock: 'top',
    items: buttonsSpecTop,
    defaults: { handler: tapHandler }
}

现在,对于tapHandler函数,第一个参数是按钮实例。所以,你可以通过这种方式获得url:

Now, for tapHandler function, the first parameter is the button instance. So, you can get the url this way:

function tapHandler(btn){
   console.log(btn);
   window.open(btn.actionUrl);
}

你不能把这些东西放在一个数组中: >

And you cannot put things in javascript this way inside an array:

defaults: [handler: tapHandler, handler: tap2Handler]

您必须使用类似于第一个的对象:

You have to use an object for that, similar to the first one:

defaults: { handler: tapHandler }

而且,您不能在单个对象中放置同一个名称的多个参数,只有一个处理程序将会出现。而对于默认值,只有一个处理程序将应用于所有项目。所以,如果你想要个别按钮的个别处理程序,每个按钮都使用处理程序侦听器。

And, you cannot put multiple parameter of same name within a single object, only one "handler" will go there. And for defaults, only one handler will be applied to all the items. So, if you want individual handlers for individual buttons, use handler listener to each of the button.

这篇关于如何在Sencha触摸工具栏中链接按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆