How to call method of a component from a controller

前端 未结 5 610
感情败类
感情败类 2020-12-14 01:35

I have a component that represent a map and after an action in my controller I want to call a method on the component to center the map. The code looks like this

<         


        
5条回答
  •  伪装坚强ぢ
    2020-12-14 02:12

    You can use on to have your component listen for an event from the controller, then you can use trigger in the controller to emit an event.

    So in your component you might have something like this:

    didInsertElement : function(){
      this.get('controller').on('recenter', $.proxy(this.recenter, this));
    },
    
    recenter : function(){
      this.get("mapView").centerMap()
    }
    

    And in your controller you could have :

    actions : {
      centerMap : function () {
        this.trigger('recenter');
      }
    }
    

提交回复
热议问题