问题
for example i have a controller like this :
App.theController = Ember.ArrayController.extend({
methodA:funtcion() {},
actions: {
methodB:function(){},
methodC:function(){}
}
});
my questions is :
- How can methodB call methodC
- 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