如何使用车把

如何使用车把

问题描述:

如何使用车把

var express = require('express'); 
 
var router = express.Router(); 
 

 
var data = { 
 

 
    curreny :{ 
 
     name:'United States dollars', 
 
     abbrev:'USD' 
 

 
}, 
 
tours:[ 
 
    {name: 'Hood River' , price:'100'}, 
 
    {name: 'Sri lanka' , price:'150'}, 
 
    {name: 'Hood River' , price:'178'} 
 
], 
 
specialsUrl:'/january-specials' 
 

 

 
} 
 

 

 
router.get('/detour',function(req,res){ 
 
    res.render('tours',{object:data}); 
 
}) 
 
module.exports = router;

以上内容我用JSON对象导出到车把的代码来访问数组元素中JSON对象。我需要在句柄文件中访问巡视数组中的巡视细节。我如何访问这些详细信息来制作h3标签中的旅游细节列表。以下是示例tour.handlebars文件。提前致谢。

<h2> Hello this is the body section</h2> 
 
<h3>currency : {{object.curreny.name}}</h3> 
 

 
<h3>tours : {{object.tours.body}}</h3>

你可以在你的tours数组迭代,然后用它在车把这样的:

{{#each object.tours}} 
    <h3>name: {{name}} </h3> 
    <h3>price: {{price}} </h3> 
{{/each}} 

如果您在模板中传递数据,那么你可以重复这样的:

{{#each tours}} 
    <h3>name :{{name}}</h3> 
{{/each}}