如何使用jsreport工作室

问题描述:

Html Code: 

    <h3>Hello Welcome</h3> 

    <div>{{jsonData}}</div> 

Script Code: 

     function beforeRender(req, res, done) { 
     require('request')({ 
      url:'http://samples.openweathermap.org/data/2.5/weather?  lat=35&lon=139&appid=b1b15e88fa797225412429c1c50c122a1', 
      json:true, 
      method: 'GET' 
     }, function(err, response, body){ 
      console.log(JSON.stringify(body)); 
      req.data = { jsonData: body }; 
      done(); 
     }); 


    } 



The api is returns following Json Data: 
{ 
"coord": { 
    "lon": 139.01, 
    "lat": 35.02 
}, 
"weather": [ 
    { 
     "id": 800, 
     "main": "Clear", 
     "description": "clear sky", 
     "icon": "01n" 
    } 
], 
"base": "stations", 
"main": { 
    "temp": 285.514, 
    "pressure": 1013.75, 
    "humidity": 100, 
    "temp_min": 285.514, 
    "temp_max": 285.514, 
    "sea_level": 1023.22, 
    "grnd_level": 1013.75 
}, 
"wind": { 
    "speed": 5.52, 
    "deg": 311 
}, 
"clouds": { 
    "all": 0 
}, 
"dt": 1485792967, 
"sys": { 
    "message": 0.0025, 
    "country": "JP", 
    "sunrise": 1485726240, 
    "sunset": 1485763863 
}, 
"id": 1907296, 
"name": "Tawarano", 
"cod": 200 

}如何使用jsreport工作室

这是jsreport代码显示API数据。现在我试图通过其余的api获取数据。我不知道如何在控制台中打印api数据,我需要帮助来了解如何使用jsrender跟随json数据并在控制台中显示。

的出将来自于所有jsreport HTTP阿贾克斯下列对象在脚本部分

“jsreport.data”

在这个对象将有我们的所有数据。您只需在脚本中打印以下代码

console.log(“data is are are:”,jsreport.data);