我发现当我转换到不同的子路由时,与父路由关联的模板也会刷新。我想避免父模板“闪烁”,因为它不需要更新。
具体来说,我有一个具有两级嵌套的路由器:
App.Router.map(function() {
this.resource("first", {path: "/first/:first_id"}, function(){
this.resource("second", {path: "/second/:second_id"}, function(){
this.route("routeone");
});
});
相应的模板:
<script type="text/x-handlebars" data-template-name="second">
Some stuff
{{outlet}}
</script>
<script type="text/x-handlebars" data-template-name="second/routeone">
Some more stuff
</script>
“第一”和“第二”路由只返回id,例如:
App.SecondRoute = Ember.Route.extend({
model: function(params){
return {id: params.second_id};
}
});
“routeone”路由从URL获取JSON:
App.SecondRouteoneRoute = Ember.Route.extend({
model: function(params){
var first_id = this.modelFor('first').id;
var second_id = this.modelFor('second').id;
var dataurl = "/_data/" + first_id + "/" + second_id;
return Ember.$.getJSON(dataurl);
},
当我从/ first / X / second / Y / routeone转换到/ first / X / second / Z / routeone时,“second”模板中的“Some stuff”文本会闪烁。这可以避免吗?