如何在Ember 1.7中从路由访问查询参数 [英] How to access query parameters from route in Ember 1.7

查看:110
本文介绍了如何在Ember 1.7中从路由访问查询参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在1.7 Ember应支持查询参数。我在控制器中使用它们没有任何问题,但我想在Route中访问它们,理想情况下在beforeModel钩子中,但是模型钩子也可以工作。

In 1.7 Ember should support Query Parameters. I have no problems using them in controller but I'd like to access them in Route, ideally in beforeModel hook but model hook would work as well.

API文档提供了beforeModel钩子的quereyParam参数,但是如果我尝试使用它,它始终是未定义的。

The API docs mention a quereyParam parameter for the beforeModel hook but if I try to use it, it is always undefined.

查询参数指南似乎表明查询参数应该可以作为模型钩子的第一个参数的一部分访问。但这也是未定义的。请参阅下面的代码示例。

The Query Parameters guide seems to suggest that the query parameters should be accessible as a part of the first parameter to the model hook. But that is also undefined. See the code below for examples.

有没有办法从Route访问查询参数?
感谢您的帮助。

Is there a way to access the query parameters from Route? Thank you for your help.

App.ApplicationRoute = Em.Route.extend({
   beforeModel: function(transition, queryParams){
       console.log(queryParams.test); //undefined at /?test=123
   },
   model: function(params){
       console.log(params.test); //undefined at /?test=123
   }
}); 


推荐答案

相当确定这是一个错误,但您可以访问在此期间通过转换对象:

Pretty sure it's a bug, but you can access them in the meantime via the transition object:

App.ApplicationRoute = Em.Route.extend({
   beforeModel: function(transition){
       console.log(transition.queryParams.test);
   }
}

这篇关于如何在Ember 1.7中从路由访问查询参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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