如何在Ember.js中重新加载当前路由? [英] How to reload current route in Ember.js?

查看:69
本文介绍了如何在Ember.js中重新加载当前路由?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Ember.js中我有路由模型。当我在路线播放列表中,如何从另一个JS函数调用回调函数来重新加载此路由(或设置新的数据到模型),可以帮助我吗?我一直在寻找文档很长时间,但对我来说没有帮助。

  App.PlaylistRoute = Ember.Route.extend {
setupController:function(controller,model){
$ .getJSON('api / playlist.php?'+ Math.random()。toString(36),function(data){
controller.set('model',data);
});
}
});

非常感谢!

解决方案

从控制器使用 transitionToRoute

  this.transitionToRoute('playlist',newModel); 

从路由使用 transitionTo

  this.transitionTo('playlist',newModel); 

例如,假设您在控制器上有一个操作

  App.PlaylistController = Ember.ArrayController.extend({
actions:{
grabNewModel:function(){
// get some新模型
this.transitionToRoute('playlist',newModel);
}
}
});


in Ember.js I have route with model. Could you help me, when I'm on route playlist how to reload this route (or set new data to model) called by callback from another JS function? I've been looking to documentation so long, but no help for me.

App.PlaylistRoute = Ember.Route.extend({
 setupController: function(controller, model) {
  $.getJSON('api/playlist.php?' + Math.random().toString(36), function (data) {
   controller.set('model', data);
  });
 }
});

Thanks a lot!

解决方案

From a controller use transitionToRoute:

this.transitionToRoute('playlist', newModel);

From a route use transitionTo:

this.transitionTo('playlist', newModel);

For example, imagine you have an action on your controller

App.PlaylistController = Ember.ArrayController.extend({
 actions: {
   grabNewModel: function(){
     //get some new model
     this.transitionToRoute('playlist', newModel);
   }
 }
});

这篇关于如何在Ember.js中重新加载当前路由?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆