javascript - 强制模板刷新 ember.js

标签 javascript ember.js refresh

我正在使用 I18n localization package处理我的应用程序的切换语言部分。它使用一个全局变量来设置所需的语言,并使用一个 json 文件来存储翻译。

由于语言的切换只是全局变量的更改,ember 不会检测到它并且不会自动呈现模板。我通过应用程序 Controller 中的操作强制执行它:

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');
            }
        );
    }
);

最佳答案

我遇到了类似的问题。我刚去了 View.rerender()在主视图上,在我的例子中是一个表单。

关于javascript - 强制模板刷新 ember.js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29533031/

相关文章:

javascript - 如何在react.js中使用onClick?

c# - 在 C# 中模拟 Javascript 'doPostBack()'

ember.js - 从按钮触发文本字段中的操作

validation - Ember 验证 : Installation

javascript - 尝试使用 Angular 将部分内容加载到我的 django 模板一侧

javascript - IE8 PRE 标签问题

javascript - 在服务器上持久化后的 Ember 更新 ID

jquery - 如何通过 jQuery 刷新页面并确保存在连接?

javascript - 使用chart.js刷新图表的图像

refresh - TextMate:在 Firefox 中预览而无需先保存文档?