【发布时间】:2013-11-15 08:00:44
【问题描述】:
我想转换为模板,但通过 JSON 请求重新加载页面内容。
换句话说,我最初通过getJSON 请求加载我的索引模板,然后我转到另一个模板来修改一些数据。稍后,我想通过具有相同 getJSON 请求的操作处理程序返回到我的初始模板(它将返回与第一个不同的另一个数据)。
App.IndexRoute = Ember.Route.extend({
model: function() {
return $.getJSON("myurl");
},
actions: {
goto: function(){
$.getJSON("myurl");
this.transitionTo('index');
}
}
});
我能够转换到我的模板并执行新的 JSON 请求,但我看到的数据是初始数据。这仅在我单击 F5 时有效,因为 ember 使用模型函数的第一个 getJSON 调用呈现模板。
编辑:
我已经找到了一个解决方案,但我想知道是否还有另一个更好的解决方案,而无需重新加载页面。
App.IndexRoute = Ember.Route.extend({
model: function() {
return $.getJSON("myurl");
},
actions: {
goto: function(){
this.transitionTo('index').then(function(){location.reload(true)});
}
}
});
提前致谢!
【问题讨论】:
标签: json ember.js getjson ember-router