每次应用程序在ember-js中进入给定路径时如何执行函数

jay*_*iya 4 ember.js

假设我有一个给定的余烬应用程序

App = Ember.Application.create()

路由器

App.Router.map(function() {
  this.resource("posts", function() {
    this.resource("post", {
      path: "/:post_id"
    })
  });
});
Run Code Online (Sandbox Code Playgroud)

每当应用程序进入给定的/:post_id时,如何执行函数?

小智 7

您可以实施App.PostRoute以指定post路线的自定义行为.如果你不这样做,Ember将在幕后制作这个课程.

activate每次激活路径时都会在路径上调用该挂钩.

例:

App.PostRoute = Ember.Route.extend({
  activate: function() {
    doSomething();
  }
});
Run Code Online (Sandbox Code Playgroud)