返回一值车把
Returning One Value Handlebars
我想知道是否可以只删除 return 我的车把模板值的一个值,尽管我正在路由我的 sql 调用。基本上我的路线是查询我的一个 table (table: images) 的所有记录,同时包括第二个 table ,其中有一个关联的记录 (table: description) 与所有被查询的记录。结果,每当我在我的页面中尝试这个对象时,我只能使用一个记录的属性 table (table: description) 作为一个循环,它显示值的次数与有正在显示的图像。车把内是否有一种方法可以将其限制为只有一个值?
这是我目前显示这条记录的方式 table 属性:
{{#image}}
<h3>{{this.description.body}}</h3>
{{/image}}
这是我的路线:
router.get('/:pattern/:color/result', function(req, res, image){
console.log(req.params.color);
console.log(req.params.pattern);
db.Images.findAll({
where: {
pattern: req.params.pattern,
color: req.params.color
},
include: [{ model: db.Description, attributes: ['body']}],
attributes: ['id', 'pattern', 'color', 'imageUrl', 'imageSource', 'description_id', 'description.body']
}).then(function(image){
//console.log(doc.descriptions_id);
res.render('pages/result.hbs', {
pattern : req.params.pattern,
color : req.params.color,
image : image
})
});
});
这是我的视图文件:
<div class="container">
<div class="row pattern-choice">
<div class="col-md-12">
<h2><i>What to wear</i></h2>
{{#image}}
<h3>{{this.description.body}}</h3>
{{/image}}
</div>
</div>
<div class="row pattern-choice">
<div class="col-md-12">
<h2><i>Inspiration</i></h2>
</div>
</div>
<div class="row">
{{#each image}}
<div class="col-lg-3 col-md-4 col-xs-6 thumb inspiration-image">
<ul>
<li>
<div class="image-placeholder">
<a href="{{ this.imageUrl }}" data-toggle="lightbox"><img class="img-responsive img-rounded" src="{{ this.imageUrl }}"></a>
</div>
<p><i>({{this.imageSource}})</i></p>
</li>
</ul>
</div>
{{/each}}
</div>
<div class="row">
<h3 class="button-choice"><a href="/" class="button-link" id="link-restart">TRY ON SOME MORE</a></h3>
</div>
</div>
请参阅 this question 关于使用把手访问数组元素。这是一个例子:
<div class="col-md-12">
<h2><i>What to wear</i></h2>
<h3>{{image.[0].description.body}}</h3>
</div>
另外,您可能想考虑将 limit
option 与您的包含查询一起使用。
我想知道是否可以只删除 return 我的车把模板值的一个值,尽管我正在路由我的 sql 调用。基本上我的路线是查询我的一个 table (table: images) 的所有记录,同时包括第二个 table ,其中有一个关联的记录 (table: description) 与所有被查询的记录。结果,每当我在我的页面中尝试这个对象时,我只能使用一个记录的属性 table (table: description) 作为一个循环,它显示值的次数与有正在显示的图像。车把内是否有一种方法可以将其限制为只有一个值?
这是我目前显示这条记录的方式 table 属性:
{{#image}}
<h3>{{this.description.body}}</h3>
{{/image}}
这是我的路线:
router.get('/:pattern/:color/result', function(req, res, image){
console.log(req.params.color);
console.log(req.params.pattern);
db.Images.findAll({
where: {
pattern: req.params.pattern,
color: req.params.color
},
include: [{ model: db.Description, attributes: ['body']}],
attributes: ['id', 'pattern', 'color', 'imageUrl', 'imageSource', 'description_id', 'description.body']
}).then(function(image){
//console.log(doc.descriptions_id);
res.render('pages/result.hbs', {
pattern : req.params.pattern,
color : req.params.color,
image : image
})
});
});
这是我的视图文件:
<div class="container">
<div class="row pattern-choice">
<div class="col-md-12">
<h2><i>What to wear</i></h2>
{{#image}}
<h3>{{this.description.body}}</h3>
{{/image}}
</div>
</div>
<div class="row pattern-choice">
<div class="col-md-12">
<h2><i>Inspiration</i></h2>
</div>
</div>
<div class="row">
{{#each image}}
<div class="col-lg-3 col-md-4 col-xs-6 thumb inspiration-image">
<ul>
<li>
<div class="image-placeholder">
<a href="{{ this.imageUrl }}" data-toggle="lightbox"><img class="img-responsive img-rounded" src="{{ this.imageUrl }}"></a>
</div>
<p><i>({{this.imageSource}})</i></p>
</li>
</ul>
</div>
{{/each}}
</div>
<div class="row">
<h3 class="button-choice"><a href="/" class="button-link" id="link-restart">TRY ON SOME MORE</a></h3>
</div>
</div>
请参阅 this question 关于使用把手访问数组元素。这是一个例子:
<div class="col-md-12">
<h2><i>What to wear</i></h2>
<h3>{{image.[0].description.body}}</h3>
</div>
另外,您可能想考虑将 limit
option 与您的包含查询一起使用。