Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

calling method from action of controller in emberjs

Tags:

ember.js

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
like image 896
MBehtemam Avatar asked Sep 29 '13 06:09

MBehtemam


People also ask

How do you call a method in Ember JS?

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


1 Answers

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.

like image 126
intuitivepixel Avatar answered Dec 05 '22 15:12

intuitivepixel