gpt4 book ai didi

ember.js - 如何观察当前路由的变化?

转载 作者:行者123 更新时间:2023-12-03 20:18:40 25 4
gpt4 key购买 nike

我要更新<title>每当位置(路线)发生变化时,页面的标签。我对观察特别感兴趣App.Router的当前路线更改 - 然后我想访问与该路线关联的 View 并更新 <title>基于 View 属性的观察者标记。

例如,如果去 /about

  • 我如何设置观察者来观察?我很难找到 currentState属性(property)或等效观察。
  • 在观察者中,我如何访问 App.AboutView与路线有关?

  • 我正在使用 1.0.0pre4
    我的目标是拥有一个 title属性(property)和 authorization观察者在 currentPath 上的每个 View 上的属性将与。我想用 title更新 document.title 的属性,以及 authorization属性对象来检查我当前用户是否可以访问路线。

    既然我这么说并且有了@Michael Grassotti 的回答,也许这些属性属于 Controller 而不是 View 。目标是访问与当前路由上下文关联的这些属性以修改 document.title并检查我的 App.CurrentUserController (为登录用户存储 User 对象模型)被授权访问当前路由。

    最佳答案

    1. What do I set the Observer to observe? I'm having trouble finding a currentState property or equivalent to observe.


    您可以关注 ApplicationController.currentPath .例如:
    App.ApplicationController = Ember.Controller.extend({
    currentPathDidChange: function() {
    path = this.get('currentPath');
    console.log('path changed to: ', path);
    window.document.title = path;
    }.observes('currentPath')
    });

    1. Within the Observer, how can I access the App.AboutView associated with the route?


    试图访问 App.AboutView来自这个观察者会很棘手,可能不是一个好主意。我不清楚为什么 View 的属性在这种情况下会有用。你能详细说明一下吗?

    关于ember.js - 如何观察当前路由的变化?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14417266/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com