簡體   English   中英

在Ember.js路由中使用動態細分

[英]Using dynamic segments with Ember.js routing

我無法理解Ember.js路由的工作方式,尤其是如何使用路由中的動態細分。

例如,如果您想從重置密碼頁面上獲取令牌並將其用於表單提交中,您將如何獲得令牌? 下面的代碼嘗試將令牌打印到頁面上,作為中間步驟,但不會呈現TokenView。 怎么了? 謝謝。

window.App = Em.Application.create({});

App.IndexView = Em.View.extend({
    template: Em.Handlebars.compile(
        '<h1>Index</h1>'
    )
});

App.ResetView = Em.View.extend({
    template: Em.Handlebars.compile(
        '<h1>reset view </h1>'
    )
});

App.TokenView = Em.View.extend({
    template: Em.Handlebars.compile(
        '<h1>token view {{token_id}}</h1>'
    )
});

App.Router = Ember.Router.extend({

    rootElement:'#content',
    location: 'hash',
    enableLogging: true,

    root: Ember.State.extend({

        index: Ember.ViewState.extend({
            route: '/',
            view: App.IndexView
        }),

        passwordReset: Ember.ViewState.extend({
            route: '/reset',
            view: App.ResetView,

            token: Ember.ViewState.extend({
                route: '/:token_id',
                view: App.TokenView
            })
        })
    })
});

App.router = App.Router.create();
App.initialize(App.router);

您應該查看有關Router的最新文檔,該文檔正在進行中,但可以在以下網址獲取:https://emberjs-staging-new.herokuapp.com/guides/outlets#toc_the-router

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM