调用emberjs中控制器的调用方法 [英] calling method from action of controller in emberjs

查看:95
本文介绍了调用emberjs中控制器的调用方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如我有一个这样的控制器:

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

我的问题是:


  1. 如何methodB调用方法C

  2. 如何methodA调用方法B


解决方案

您必须使用 this.send([methodName])才能正确调用您的方法:

  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(){
//如何方法调用方法B
this.send('methodB ');
console.log('methodA called');
},
actions:{
methodB:function(){
//如何方法B调用methodC
this.send('methodC');
console.log('methodB called');
},
methodC:function(){
console。 log('methodC called');
}
}
});

这里有一个简单的 jsbin 作为一个操场。



希望它有帮助。


for example i have a controller like this :

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

my questions is :

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

解决方案

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.

这篇关于调用emberjs中控制器的调用方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆