如何从视图将操作从一个控制器/路由器发送到另一个控制器/路由器

How do you send an action from one controller/router to another from a view?

本文关键字:路由器 控制器 另一个 一个 视图 操作      更新时间:2023-09-26

我在视图中,我想将操作发送到与我所在的视图不同的控制器或路由器。我该怎么做?

App.FormView = Ember.View.extend ({
    actions: {
        clicked: function() {
            context = this.get("context");
                App.OtherViewController.send("clicked", context); //this doesn't work
            // this.get("controller").send("clicked", context); // this sends to the current controller
        }
    }
});

如果你的FormController needs一些ThingController你可以通过做this.get('controller.controllers.thing')把它放在FormView里。 从内部FormController你会使用this.get('controllers.thing').

App.FormController = Ember.ObjectController.extend({
  needs : ['thing']
});
App.FormView = Ember.View.extend ({
    actions: {
        clicked: function() {
            context = this.get("context");
            // this sends to the ThingController
            this.get("controller.controllers.thing").send("clicked", context); 
        }
    }
});