在路由之间传递隐藏参数 [英] Passing hidden parameters between routes
问题描述
我对Ember.js很陌生,试图创建一个应用程序,我需要浏览日期和记录的优先次序。
I am much new to Ember.js, and trying to create an application where i need to surf through dates and privecy of records
我想做的是,我需要通过ember路由传递一个变量值,而不在url上显示
What i want to do is, i need to pass one variable value through ember routes without showing it on url
appcication_routes.js.coffee
App.Router.map ->
@resource 'user', { path: '/user/:user_id' }, ->
@resource 'user_feed', { path: '/feed' }, ->
@route 'posts', { path: '/:date' }
user_routes.js.coffee
App.UserFeedIndexRoute = App.Route.extend
activate: ->
controller = @controllerFor('user_feed.index')
controller.set 'checkPrivate', false
redirect: ->
@transitionTo 'user_feed.posts', @modelFor('user'), 'today'
App.UserFeedPostsRoute = App.Route.extend
activate: ->
controller = @controllerFor('user_feed.posts')
model: (params) ->
...
对于从下面使用的控制器i的转换
For transition from controller i used below string
@transitionToRoute 'user_feed.posts', @get('user'), newDateString
我需要将 checkPrivate 的值传递到 UserFeedPosts ,但不显示给url,我还需要调用
I need to pass value of checkPrivate to UserFeedPosts but without showing it to url, also i need to call the route againg on date change or checkPrivate value change.
我已经google了很多,但是没有成功。
I have googled it a lot but with zero success.
推荐答案
您可以使用共享控制器(控制器/rel =nofollow> Ember指南)保存私有变量的状态。
You could use a shared controller (Ember Guide) which saves the state of the private variable.
App.ApplicationController = Em.Controller.extend({
checkPrivate: null
});
然后,如果要在特定控制器中访问此值, strong>需求。
Then, if you want to have accessible this value in a specific controller, you could import it with needs.
App. UserFeedPostsController = Em.ArrayController.extend({
needs: ['application']
});
App.ApplicationController = Em.Controller.extend({
needs: ['application']
});
如果您的案例不需要访问其他控制器的数据,具体控制器从任何路由为:
If your case does not require to have accesible the data from the other controller, you can always access a specific controller from any route as:
this.controllerFor('application');
这篇关于在路由之间传递隐藏参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!