0
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 生成コードです。現在、残りの API を介してデータを取得しようとしています。API データがコンソールに出力される方法がわかりません。json データに続いて jsrender を使用して反復処理し、コンソールに表示する方法について助けが必要です。

4

1 に答える 1

0

出力は、スクリプト セクションの次のオブジェクトのすべての jsreport http ajax に含まれます。

「jsreport.data」

このオブジェクトには、すべてのデータが含まれます。次のコードをスクリプトに出力するだけです

console.log("利用可能なデータは:",jsreport.data);

于 2017-07-13T07:52:34.937 に答える