0

I am trying to create a route to add a child entity on a parent. My router looks something like this. I have a nested route in the parent's show, which I'm pretty sure is wrong. Doing this seems to stop the URL changing between page transition, and when I navigate to the addChild route from the parent's template through the {{action doAddChild href=true}}, the :parent_id in the URL is undefined. I'm guessing this is because I'm not setting the context on the action which should be the parent, but where do I get that from?

What's the best way to achieve this? I'm obviously barking up the wrong tree...

App.Router = Ember.Router.extend
    enableLogging: true
    root: Ember.Route.extend
        index: Ember.Route.extend
            route: "/"
        parents: Ember.Route.extend
            route: "/parents"
            doShow: Ember.Route.transitionTo('show')
            index: Ember.Route.extend
                route: "/"
                connectOutlets: (router) ->
                    router.get("applicationController").connectOutlet "parents"
            show: Ember.Route.extend
                route: "/:parent_id"
                doAddChild: Ember.Route.transitionTo('addChild')
                modelType: App.Parent
                connectOutlets: (router, parent) ->
                    router.get("applicationController").connectOutlet "parent", parent
                addChild: Ember.Route.extend
                    route: "/addChild"
                    connectOutlets: (router) ->
                        router.get("applicationController").connectOutlet "addChild"
4

1 に答える 1

0

最初の問題はショーのルートです。遷移しないとおっしゃっていましたが、これはルータがリーフ ノードにしか正しく遷移できないためです。現在の答えは、ダミーのインデックス ルートを追加することです。

Router = Ember.Router.extend
    enableLogging: true
    root: Ember.Route.extend
        index: Ember.Route.extend
            route: "/"
        parents: Ember.Route.extend
            route: "/parents"
            doShow: Ember.Route.transitionTo('show.index')
            index: Ember.Route.extend
                route: "/"
                connectOutlets: (router) ->
                    router.get("applicationController").connectOutlet "parents"
            show: Ember.Route.extend
                route: "/:parent_id"
                doAddChild: Ember.Route.transitionTo('addChild')
                connectOutlets: (router, parent) ->
                    router.get("applicationController").connectOutlet "parent", parent
                index: Ember.Route.extend
                    route: "/"
                addChild: Ember.Route.extend
                    route: "/addChild"
                    connectOutlets: (router) ->
                        router.get("applicationController").connectOutlet "addChild"

指が交差し、他のすべても修正されます。

于 2012-07-17T07:33:32.120 に答える