在 Ember 2 中,对于查询字符串为 的 URL ?q[a]=1&q[b]=2
,如何在控制器中获取这些参数?
我能够得到一个字符串 ( q=foo
) 和一个数组 ( q[]=1&q[]=2
),但我无法得到上面提到的对象。
在 Ember 2 中,对于查询字符串为 的 URL ?q[a]=1&q[b]=2
,如何在控制器中获取这些参数?
我能够得到一个字符串 ( q=foo
) 和一个数组 ( q[]=1&q[]=2
),但我无法得到上面提到的对象。
您可以访问 中的参数route
并将它们发送到controller
by:
setupController(controller, model, transition) {
this._super(...arguments);
// transition.params contains params in the url
// this.get('router.url') contains all query params
// your method in the controller to handle the params
controller.setQueryParams( ...your params... );
}