calling method from action of controller in emberjs

久未见 提交于 2019-12-20 16:49:13

问题


for example i have a controller like this :

App.theController = Ember.ArrayController.extend({
  methodA:funtcion() {},
  actions: {
    methodB:function(){},
    methodC:function(){}
  }
});

my questions is :

  1. How can methodB call methodC
  2. How can methodA call methodB

回答1:


You have to use this.send([methodName]) in order to get your methods called correctly:

var App = Ember.Application.create({
  ready: function() {
    console.log('App ready');
    var theController = App.theController.create();
    theController.send('methodC');
  }
});

App.theController = Ember.ArrayController.extend({
  methodA:function(){
    //How can methodA calling methodB
    this.send('methodB');
    console.log('methodA called');
  },
  actions:{
    methodB:function(){
      //How can methodB calling methodC
      this.send('methodC');
      console.log('methodB called');
    },
    methodC:function(){
      console.log('methodC called');
    }
  }
});

Here a simple jsbin as a playground.

Hope it helps.



来源:https://stackoverflow.com/questions/19075263/calling-method-from-action-of-controller-in-emberjs

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!