Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ember.js/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ember.js 如何在应用程序每次进入ember js中的给定路径时执行函数_Ember.js - Fatal编程技术网

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

Ember.js 如何在应用程序每次进入ember js中的给定路径时执行函数,ember.js,Ember.js,假设我有一个给定的余烬应用程序 App=Ember.Application.create() 路由器 App.Router.map(function() { this.resource("posts", function() { this.resource("post", { path: "/:post_id" }) }); }); 每当应用程序输入给定的/:post_id时,我如何每次执行一个函数?在此处使用路由器请求生命周期中的一个钩子:您可以实现App

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

App=Ember.Application.create()

路由器

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

每当应用程序输入给定的/:post_id时,我如何每次执行一个函数?

在此处使用路由器请求生命周期中的一个钩子:

您可以实现
App.PostRoute
来指定您的
post
路由的自定义行为。如果没有,Ember将在幕后创建这个类

每次激活路线时,
activate
钩子在路线上被调用

例如:

App.PostRoute = Ember.Route.extend({
  activate: function() {
    doSomething();
  }
});

您应该使用
setupController()
model()
hook并不总是被调用,即当您使用
{{linkTo}
link.Yes.转换到路由时。。同意。。。我正在编辑“仅指向博客帖子列表”的答案。我尝试过这样做。它没有按预期工作。在帖子1和帖子2之间切换时的示例。。。应再次调用激活功能。以下是