强制刷新Ember.js模板

4
我正在使用I18n本地化包来处理应用程序语言切换的部分。它使用全局变量来设置所需的语言,并使用json文件存储翻译内容。
由于语言切换只是全局变量的更改,Ember无法检测到并自动呈现模板。我通过在应用程序控制器中添加一个操作来强制执行。
Extranet.ApplicationController = Ember.ObjectController.extend(
{
    actions:
    {
        localToFr: function()
        {

            this.localisation('fr'); // this changes the global variable
            this.get('target.router').refresh(); // this is what refresh the template
        },
        localToEn: function()
        {
            this.localisation('en');
            this.get('target.router').refresh();
        }
    },
    localisation: function(lg)
    {
        I18n.locale = lg;
    }
})

我对该解决方案有两个问题: 1)应用程序模板未通过我的重新呈现进行更新

this.get('target.router').refresh();

2) 我的另一个问题是,它不能在不请求服务器访问的模板上正常工作(例如:路由“authSession”的嵌套)。

Extranet.Router.map(function()
    {
        this.resource(
            'parkings', {path:'/'}, function ()
            {
                this.route('parking', {path:'/parking/:parking_id'});
                this.route('historique', {path:'/parking/:parking_id/historique'});
                this.route('sessAct', {path:'/parking/:parking_id/sessAct'});
                this.route('rapport', {path:'/parking/:parking_id/rapport'});
            }
        );
        this.resource(
            'authSession', function ()
            {
                this.route('login');
                this.route('logout');
            }
        );
    }
);

你有不使用https://github.com/jamesarosen/ember-i18n的理由吗?我打算自己实现翻译,所以很好奇。 - Keo
不,我没有。只是I18n提供的已经足够我使用了(顺便说一下,我只使用这个包中的链接https://github.com/fnando/i18n-js/blob/master/app/assets/javascripts/i18n.js,因为我不使用rails作为我的后端),而且我正在遵循Robin Ward的一个相当古老但仍然可用的教程链接 - AlexandreDz
1个回答

1
我遇到了类似的问题。我只是在主视图上使用了View.rerender(),这是一个表单。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接