0

我在一个容器中有两个标签。当我单击某个按钮时,我想更改标签值。我尝试了很多方法。但它没有改变。

这是我的视图代码:

   Ext.define('MortgageCalculator.view.CalculateScreen', {
    extend : 'Ext.Panel',

    config : {
        scrollable : true,
        items : [{
            xtype : 'titlebar',
            docked : 'top',
            ui : 'green',
            title : 'MORTGAGE CALCULATOR'
        }, {

            xtype : 'container',
            layout : {
                type : 'vbox'
            },
items : [{

xtype : 'button',
                name : 'submitbtn',
                text : 'Calculate Monthly',
                ui : 'confirm',
                width: 200,
                height : 40,
                margin : 'auto'
            }, {

                xtype : 'container',
                id:'capandintsum',
                layout : {
                    type : 'hbox'
                },
                items : [{
                    xtype : 'label',
                    layout : 'fit',
                    html : 'Capital & Interest',
                    flex : 1,
                    margin : '60 0 0 20'
                }, {
                    xtype : 'label',
                    layout : 'fit',
                    name:'cap&int',
                    id : 'cap&int',
                    html : '0',
                    flex : 1,
                    margin : '60 0 0 20'
                }]
            },

            {
                xtype : 'container',
                layout : {
                    type : 'hbox'
                },
                items : [{
                    xtype : 'label',
                    layout : 'fit',
                    html : 'Interest Only',
                    flex : 1,
                    margin : '20 0 0 20'
                }, {
                    xtype : 'label',
                    layout : 'fit',
                    name:'intonly',
                    id : 'intonly',
                    html : '0',
                    flex : 1,
                    margin : '20 0 0 20'
                }]
        }]
    }
});

对于控制器,我使用以下代码:

Ext.define('MortgageCalculator.controller.Calculate', {         
        extend : 'Ext.app.Controller',
        config : {
            refs : {
                submitbtn : 'button[name=submitbtn]',
                capandintlbl : '#intonly'
                // capandintlbl :  '#cap&int', 
                // onlyintlbl : '#intonly' 
            },
            control : {
                submitbtn : {
                    tap : 'onSubmitButtonTap'
                },
            }
        },


        onSubmitButtonTap : function(button, e, options) {
                                this.getCapandintlbl.setHtml('hello, it is changed');           }



    })

请帮忙..

4

2 回答 2

1

只需为 label 设置一个值,您可以使用 label 中描述的 setText 方法

看到这个链接

 yourLabel.setText('value');
于 2013-01-20T09:09:03.897 回答
1

终于我能够以这种方式制作:

var me = this; 
var labelfield = me.getCapandintlbl(); 
labelfield.setHtml('it is changing');

谢谢雷切尔..

于 2013-01-20T13:05:16.503 回答