2

背景 : sencha touch 2 を使用して MVC アプリケーションに取り組んでいます。2 つのタブを持つページに取り組んでいます。最初のタブ内には、タイトル バー内にボタンがあります。

問題: ボタン ハンドラーから他の関数​​を呼び出すことができません。呼び出し関数の範囲に問題があると思います。

これが私のコードです。

Ext.define('WUPOC.view.WUHomePage', {
  extend: 'Ext.TabPanel',
  requires:['Ext.TitleBar','Ext.dataview.List','Ext.data.proxy.JsonP'],
  alias: 'widget.wuHomePageView',

  config: {
    fullscreen: true,

    defaults: {
      styleHtmlContent: true
    },

    items: [{
      title: 'Home',
      iconCls: 'home',

      items: [{
        xtype: 'titlebar',
        title: 'Hello',
        docked: 'top',
        items: [{
          xtype: 'button',
          text: 'LogOut',
          ui: 'action',
          itemId: 'newButton',
          align: 'right',
          handler : function(btn){
            console.log('LogOut is tapped');  // This is printed
            this.up.onNewButtonTap();  // Throws error
          }
        }],
      }],
    }, {
      title: 'Contact',
      iconCls: 'user',
      html: 'Contact Screen'
    }]
  },

  onNewButtonTap: function () {
    alert('newNoteCommand');
  },
});

以下のようなエラーが発生しています。

Uncaught TypeError: Object function (selector) {
        var result = this.parent;

        if (selector) {
            for (; result; result = result.parent) {
                if (Ext.ComponentQuery.is(result, selector)) {
                    return result;
                }
            }
        }
        return result;
    } has no method 'onNewButtonTap' 

ボタンのスコープの設定に問題があると思います。親切に助けてください。

ありがとうございました

4

1 に答える 1

4

まず、upは関数なので、次のように呼び出す必要があります。

this.up();

次にthis.up()、メソッドを持たないボタンのコンテナーにのみもたらしますonNewButtonTap。適切なコンポーネントを取得するまで up() を実行し続けることもできますが、これはより賢い方法です。

  • ビューに xtype を追加する
  • この xtype を up 関数のセレクターとして使用します。this.up('myXType').onNewButtonTap();

お役に立てれば

于 2012-12-13T22:25:05.910 に答える