gpt4 book ai didi

ember.js - 在文件夹中组织 ember 模板

转载 作者:行者123 更新时间:2023-12-04 23:23:11 25 4
gpt4 key购买 nike

我有一个这样的路由器 map :

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'});
});
});

模板文件存储在“templates/eng”文件夹中;对于“home”和“eng.rent”路由,一切正常:Ember 可以自己找到模板文件所在的位置;但对于其他路线,我必须指定模板的位置,例如:
Importclimbing.EngRentBoulderSmallRoute = Importclimbing.StdEngRoute.extend({
renderTemplate: function() {
this.render('eng/boulderSmall');
}
});

有人可以解释 Ember 如何查找模板文件吗?例如,如果我没有如上所述为 EngRentBoulderSmallRoute 指定“renderTemplate”,模板将不会呈现(即使我将“boulderSmall.hbs”文件放入“template”文件夹而不是“template/eng”;因此, Ember 默认在哪里查找这个模板?如果我想将“boulderSmall.hbs”存储到“templates/eng/rent”文件夹中,我应该将哪个路径传递给 renderTemplate 函数?

最佳答案

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

首先你需要重命名 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'});
});
});

然后您的模板和文件夹应该以这种方式命名。
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

我希望这有帮助。
干杯

关于ember.js - 在文件夹中组织 ember 模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18928342/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com