2015-11-02 24 views
0

我有這個作爲我的router.js。需要注意的是它沒有應用途徑:應用程序路由是否會自動加載並在Ember應用程序中加載application.hbs?

import Ember from 'ember'; 
import config from './config/environment'; 

var Router = Ember.Router.extend({ 
    location: config.locationType 
}); 

Router.map(function() { 
    this.route('todos', { path: '/'}); 
}); 

export default Router; 

當我打的回家路,我看到我的application.hbs模板和模板todos.hbs加載在出口。這是我的應用程序.hbs:

<section id="todoapp"> 
    <header id="header"> 
    <h1>todos header in application.hbs</h1> 
    </header> 

    {{outlet}} 
</section> 

<footer id="info"> 
    <p> 
    Footer in application.hbs. Double-click to edit a todo 
    </p> 
</footer> 

爲什麼我的application.hbs被加載?

我想知道子玉也加載在我的路線文件夾中的todos.js這是這樣的:

import Ember from 'ember'; 

export default Ember.Route.extend({ 
    model() { 
    let todos = [ 
     { 
     title: 'Learn Ember', 
     complete: false, 
     }, 
     { 
     title: 'Solve World Hunger', 
     complete: false, 
     } 
    ]; 
    return todos; 
    } 
}); 

這是我todos.hbs模板:

<h2>Todos Template</h2> 

<ul> 
    {{#each model as |todo|}} 
     <li> 
      {{todo.title}} 
     </li> 
    {{/each}} 
</ul> 

的主要問題
1.爲什麼我的application.hbs在我到達主路時被加載?
2.什麼是導出默認值?
3.什麼是從'燼'導入Ember行? '燼'從哪裏來?

回答

1
  1. 應用程序路由在每個Ember.js應用程序中加載。請參閱http://guides.emberjs.com/v2.1.0/routing/defining-your-routes/#toc_the-application-route

  2. 導出默認值是ES6模塊規範的一部分。請參閱http://exploringjs.com/es6/ch_modules.html將模塊導入到另一個模塊內時,將返回的對象或變量作爲要導入的默認內容。

  3. 'ember'命名空間內置於Ember CLI中。它的默認導出是Ember變量,它曾經是Ember先前版本中的一個全局變量。

+0

哦我看,這裏的含義是,Ember使用ES6? – Jwan622

+1

是的,默認情況下Ember CLI會傳輸ES6/ES2015。 – Gaurav