1

MVC アーキテクチャ パターンを使用してコントローラー内の画像にスワイプ リスナーを追加するにはどうすればよいですか? 現在、以下のようにビューにリスナーを追加することでこれを行っています。

MyView.js

itemId: 'houseImage',
xtype: 'image',
src: 'resources/img/house.png',
width: 225,
height: 180, 
  listeners: {
    initialize: function(c) {
      this.element.on({
      swipe: function(e, node, options) {
         if(e.direction == "left") {
             alert("left");
         } else if(e.direction == "right"){
             alert("right");
         } 
      }
    }
  });
}

ここで、コントローラーにリスナーを配置する MVC パターンを利用したいと思います。問題は、xtype: 'image' にイベント 'swipe' がないため、swipe から継承するどのイベントを呼び出す必要があるかわかりません。このようなものがうまくいくかもしれないと思ったのですが、

MyController.js

Ext.define('StromRechner.controller.Settings', {
    extend: 'Ext.app.Controller',
        
    config: {
        refs: {
            houseImage: '#houseImage',
        },
        control: {
            'myview image':{
            swipe: 'swipeImage'
        } 
    }
},
swipeImage: function(){
    this.getHouseImage().on({
        swipe: function(e, node, options){
            if(e.direction == "left") {
                alert("Hey! I swipe left");
            } else if(e.direction == "right"){
                alert("Hey! I swipe right");
            }
        });
    }
});

ありがとう、

4

1 に答える 1