使用ember.js设置页面标题 [英] Setting page title with ember.js

查看:74
本文介绍了使用ember.js设置页面标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

设置页面标题的最佳方法是什么,以便在网址之间转换时,标题将反映新的状态?有没有办法设置路由器来做到这一点?

What is the best way to set the page's title, so that when transitioning between urls, the title will reflect the new state? Is there a way to set the Router to do this?

我想要一种方法,允许我为每个状态设置页面标题架构。所以,如果路由有参数,它们将被传递到pageTitle:

I want a method that allows me to set a page title schema for each state. So, if the route has parameters, they will be passed into the pageTitle:

sessions : Ember.Route.extend({
       route:"/sessions",
       connectOutlets : function(router) {
           //...
       },
       pageTitle:function(){
            return "Sessions";
       },
   })

我打开关于如何最好地在模型或其他地方实现这种类型的功能的任何建议。

I'm open to any suggestions as to how it is best to implement this type of functionality on the Model or someplace else.

推荐答案

方法:

Ember.Route.reopen({
    enter: function(router) { 
        this._super(router)

        # Set page title
        name = this.parentState.get('name')
        if (!Em.none(name)) {
            capitalizedName = name.charAt(0).toUpperCase() + name.slice(1)
            $(document).attr('title', "Website - " + capitalizedName)
        }
   }
})

使用navigateTo提出了一些问题,最终更可靠至少我的情况更清洁。

A few issues came up with using navigateTo, this ended up being more reliable and cleaner for my situation at least.

这篇关于使用ember.js设置页面标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆