簡體   English   中英

將值綁定到來自不同路由的application.hbs

[英]bind values to application.hbs from different routes

在Ember.js( 2.5.1版 )中,我的application.hbs中包含以下代碼:

<div class="content-wrapper">
    <section class="content-header">
        <h1>
            {{title}}<small>{{description}}</small>
        </h1>
    </section>
    <section class="content">
        {{outlet}}
    </section>
</div>

我應該在哪里聲明{{title}}{{description}}屬性,以便可以根據當前路線進行更改? 我想生成一個適用於索引路由的應用程序控制器( ember g controller application ),但是,如果我導航到應用程序中的其他路由,則無法更改這些屬性。

我會像這樣設計我的application.hbs

    {{partial "app_navbar"}}
        <div class="container">
           {{outlet}}
        </div>
    {{partial "app_footer"}}

並創建一個與路由相關的標頭,我將創建一個組件內容標頭

模板/組件/內容header.hbs

<div class="content-header">
   <h1> {{params.title}} - <small> {{params.description}} </small> </h1>
</div>

在您自定義路線的控制器中

export default Ember.Controller.extend({
    navbarParams: {
       title: 'Foo',
       description: 'Bar'
    }
});

在您的自定義路線模板中

{{content-header params=navbarParams}}

{{! Your other content here}}

暫無
暫無

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

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