1

Sencha Touch 2 を使用しています。ボタン宣言があり、EVENT クリックでテキスト プロパティを変更したいと考えています。

これは私のコードです。動作しません..それを解決する方法はありますか?

var accessibilityButton = {
        id: 'accessibilityButton',
        xtype: 'button',
        ui: 'custom-btn-confirm',
        maxWidth: '360px',
        centered: true,
        flex: 1,
        scope: this,
        style: 'color: #ffffff',
        text: 'Larger Text',

        handler: function changeStyle() {

            // Swap the CSS for Accessibility             
            var i, a, url, btn;
            btn = document.getElementById('accessibilityButton');

            for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
                if(a.getAttribute("rel").indexOf("style") != -1) {
                    url = a.href;

                    if(url.lastIndexOf('app.css') !== -1) {
                        a.href = 'resources/css/app-accesibility.css';          
                        btn.innerHTML = 'Default Text';
                    }
                    else {
                        a.href = 'resources/css/app.css';
                        btn.innerHTML = 'Larger Text';   
                    }
                } 

            }

        }

    };
4

1 に答える 1

2

ハンドラー関数はボタン コンポーネントのスコープ内で呼び出される必要があるため、代わりに次のようにしてみてください。

handler: function changeStyle() {
    this.setText('text');
}

編集

またはスコープを変更した場合:

scope: this,
handler: function changeStyle(btn) {
    btn.setText('text');
}

2 番目のバージョンは常に機能することに注意してください。

于 2012-10-01T13:01:43.470 に答える