2016-07-27 35 views
0

我是新的Extjs用戶我定義了控制器裏面的導航,但不工作。請幫忙。Extjs控制器定義裏面的導航

Ext.define('MyApp.controller.Navigation', { 
    extend: 'Ext.app.Controller', 
    alias: 'widget.navigationController', 

    views: ['Navigation'], 


    refs : [{ 
     ref: 'navigationView', 
     selector: 'navigation' 
    }], 


    init: function(application){ 
     console.log('controller init'); 
     this.control({ 
      'navigation': { 
       'golocale': this.goLocale, 
       'gobrand': this.goBrand, 
       'gosize': this.goSize, 
       'goarticle': this.goArticle, 
       'gogender': this.goGender, 
       'goprofile': this.goProfile, 
       scope: this 
      } 
     }); 
    }, 


    goLocale: function(link){ 
     console.log('locale clicked'); 
     console.dir(link); 
    }, 


    goBrand: function(link){ 
     console.log('brand clicked'); 
     // Also tried: 
     // var viewport = this.getView('Viewport').create(); 
     var viewport = link.up('viewport'); 
     console.dir(viewport); 
    }, 

控制檯錯誤波紋管

MyApp.controller.Navigation.addListener(): The specified callback function is undefined 
+1

其他方法在哪裏? 'goSize','goArticle'等?這可能是爲什麼它拋出異常。 –

回答

0

你提供給你的函數 「控制」 的對象。

在該對象內部,this指向對象,而不是指向控制器。請嘗試

init: function(application){ 
    console.log('controller init'); 
    var me = this; // "me" is scope to controller 
    this.control({ 
     'navigation': { 
      'golocale': me.goLocale, 
      'gobrand': me.goBrand, 
      'gosize': me.goSize, 
      'goarticle': me.goArticle, 
      'gogender': me.goGender, 
      'goprofile': me.goProfile, 
      scope: me 
     } 
    });