在文件夹中组织ember模板

Cer*_*ler 4 ember.js

我有这样的路由器地图:

this.resource('eng', function(){
    this.route('home');
    this.resource('eng.rent', {path: 'rent' }, function(){
        this.route('boulderSmall', {path: 'boulder-small'});
        this.route('boulderXl', {path: 'boulder-xl'});
    });     
});
Run Code Online (Sandbox Code Playgroud)

模板文件存储在"templates/eng"文件夹中; 对于"home"和"eng.rent"路线,一切都很好:Ember可以自己找到模板文件的位置; 但对于其他路线,我必须指定模板的位置,例如:

Importclimbing.EngRentBoulderSmallRoute = Importclimbing.StdEngRoute.extend({
    renderTemplate: function() {
        this.render('eng/boulderSmall');
    }
});
Run Code Online (Sandbox Code Playgroud)

有人可以解释Ember如何查找模板文件吗?例如,如果我没有为EngRentBoulderSmallRoute指定"renderTemplate",则模板将不会呈现(即使我将"boulderSmall.hbs"文件放入"template"文件夹而不是"template/eng";等等,默认情况下Ember会查找此模板?如果我想将"boulderSmall.hbs"存储到"templates/eng/rent"文件夹中,我应该将哪条路径传递给renderTemplate函数?

kiw*_*ver 5

您的文件夹结构应如下所示.

首先,您需要重命名eng.rent路由,rent以便路由器看起来像这样

this.resource('eng', function(){
    this.route('home');
    this.resource('rent', {path: 'rent' }, function(){
        this.route('boulderSmall', {path: 'boulder-small'});
        this.route('boulderXl', {path: 'boulder-xl'});
    });     
});
Run Code Online (Sandbox Code Playgroud)

然后你的模板和文件夹应该这样命名.

templates          ## this is a folder
  |--eng           ## this is a folder
      |--home.hbs
  |--rent      ## this is a folder
      |--boulder_small.hbs
      |--boulder_xl.hbs
  application.hbs
  eng.hbs
  rent.hbs
Run Code Online (Sandbox Code Playgroud)

我希望这有帮助.干杯