2017-07-06 34 views
0

如何使用車把

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>

回答

0

你可以在你的tours數組迭代,然後用它在車把這樣的:

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

如果您在模板中傳遞數據,那麼你可以重複這樣的:

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