簡體   English   中英

如何為模板Ember 2提供索引路由?

[英]How do I supply an index route with a template Ember 2?

我想創建一個余燼應用程序,如下所示:

var app = Ember.Application.create({
  rootElement: document.getElementById('root'),
  name: 'my-application',
  IndexRoute: Ember.Route.extend({
      model: function() {
        console.log('model');
      },
      afterModel: function(model, transition) {

      },
      template: Ember.Handlebars.compile('<div id="test"></div>'),
    }),
  locationType: 'hash',

});

問題是我沒有在DOM中獲得測試div。 怎么會?

http://jsbin.com/koyihapuze/edit?html,js,控制台,輸出

1)在您的代碼中this.namespace.TEMPLATES是未定義的(在resolver內部),因此您可以修復如下代碼

  resolveTemplate: function(parsedName) {
    var templatePath = parsedName.fullNameWithoutType.replace('.', '/');
    var template = this.namespace.TEMPLATES && this.namespace.TEMPLATES[templatePath];
    if (!template) {
      template = this._super(parsedName);
    }
    return template;
  },

在應用程序容器內找到新的div.ember-view元素之后

2)template不是路由的屬性(如您的代碼所示),您可以在路由器中使用template或templateName定義ApplicationView並解決解析器錯誤

PS最好使用ember-cli從Ember開始

暫無
暫無

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

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