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

时间:2013-09-23 03:09:37

标签: javascript ember.js

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

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
        }
    }
});

1 个答案:

答案 0 :(得分:1)

如果FormController needs某些ThingController,您可以FormView通过this.get('controller.controllers.thing')进入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); } } });

{{1}}