我正在使用 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/