Emberjs复杂路由 [英] Emberjs Complex Routing
问题描述
在我的应用程序有一个客户端的成员选择瓶子和管理部分管理成员,瓶子,储物柜等,使用相同的型号,所以我想我的路由器应该是这样:
In my application there is a client side for members to select bottles and an admin section to manage members, bottles, lockers etc. that both use the same models so I figured that my my router should look like this:
App.Router.map ->
@.route "signin" #Restuarant signs in to the application
@.resource "member", ->
@.route "signin" #Members sign in to see their bottles
@.resource "member", path: ":member_id", ->
@.resource "bottles", ->
@.route "select"
@.resource "transcations", ->
@.route "create"
@.resource "transcation", path: ":transcation_id", ->
@.resource "admin", ->
@.route "signin" #Restaurant signs in to manage
@.resource "members", ->
@.route "create"
@.resource "member", path: ":member_id", ->
@.resource "bottles", ->
@.route "create"
@.resource "bottle", path: ":bottle_id", ->
@.route "edit"
@.resource "transcations", ->
@.resource "transcation", path: ":transcation_id", ->
@.resource "lockers", ->
@.route "create"
@.resource "locker", path: ":locker_id", ->
@.resource "lockertype", path: "types", ->
@.resource "lockertype", path: ":locker_type_id", ->
@.route "edit"
@.route "create"
了解管理员下的资源将替换具有相同名称的成员的资源。
I understand that the resources under admin will replace the resources for the members that have the same name.
解决这个问题的最佳模式是什么?
What would be the best pattern to solve this?
我现在的解决方案是命名空间(kinda?)这样的资源:
My current solution would be to namespace (kinda?) the resources like this:
@.resource "member", ->
@.route "m.signin" #Members sign in to see their bottles
@.resource "m.member", path: ":member_id", ->
@.resource "m.bottles", ->
@.route "select"
@.resource "m.transcations", ->
@.route "create"
@.resource "m.transcation", path: ":transcation_id", ->
有更好的方法吗?这是可怕的吗?我一直在查找EMBER.NAMESPACE,但我不明白我该如何使用它。
Is there a better way? Is this way terrible? I've been looking up EMBER.NAMESPACE but I don't understand how I would use it.
在github上的相关讨论:
Relevant discussions on github:
https://github.com/emberjs/ember.js/issues / 683
https://github.com/emberjs/ember .js / pull / 1925
推荐答案
如果声明嵌套资源,其名称必须包含父资源的名称dot:'members.member','members.member.bottles'等。尾部路由的名称更简单('signin'insted of'member.signin')。
您可以使用chrome扩展( Ember Inspector )。
If you declare nested resource, it's name must contain parent resource's name ended with dot: 'members.member', 'members.member.bottles', etc. Names of tail routes are simpler ('signin' insted of 'member.signin'). You can observe all application's routes with help of chrome extension (Ember Inspector).
从9月14日更新:
我用于旧版本的Ember,错过了路由系统中的更新。在上一个Ember版本(1.7.0)中不需要 this.resource
调用。这意味着你只能使用 this.route
方法,这更容易和更清楚: http://emberjs.jsbin.com/bukogojuzeni/1/edit?html,js,output
Update from 14 Sep:
I used to an old versions of Ember and somehow missed an update in routing system. There is no need for this.resource
call in the last Ember version (1.7.0). This means you can use only this.route
method, which is easer and more clear: http://emberjs.jsbin.com/bukogojuzeni/1/edit?html,js,output
这篇关于Emberjs复杂路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!