請幫我解決這個問題。我是node
以及json
。
一些事情一定會變得非常糟糕。json發送查看,但無法從中獲取id玉模板
extends layout
block content
h3 Trips selection #{trips} //shows following json in the view
form.form-horizontal(id="Findtrips", accept-charset="UTF-8",
action="#", method="post" enctype="multipart/form-data")
each trip in trips
p #{trip.tripId} //doesnt pusblish anything
#{trips}
給出如下:
{
"onwardTrips": [{
"tripId": "1285170",
"fromCity": "Singapore",
"toCity": "Malacca",
"operatorCode": "SA",
"operatorName": "Starmart Express",
"departTime": "2014-01-20 20:00:00.0",
"busType": "Executive",
"pickupPointDetails": [{
"pickupPointId": "78",
"departureTime": "2014-01-20 20:00:00.0",
"pickupPointName": "Golden Mile Tower, Beach Road"
}],
"dropoffPointDetails": [{
"dropOffPointName": "Melaka Sentral",
"dropOffPointId": "1285170"
}],
"fareDetails": {
"adultFare": "65.0"
}
},
{
"tripId": "1285254",
"fromCity": "Singapore",
"toCity": "Malacca",
"operatorCode": "SA",
"operatorName": "Starmart Express",
"departTime": "2014-01-20 23:00:00.0",
"busType": "Executive",
"pickupPointDetails": [{
"pickupPointId": "78",
"departureTime": "2014-01-20 23:00:00.0",
"pickupPointName": "Golden Mile Tower, Beach Road"
}],
"dropoffPointDetails": [{
"dropOffPointName": "Melaka Sentral",
"dropOffPointId": "1285254"
}],
"fareDetails": {
"adultFare": "65.0"
}
}],
"errorCode": 0
}
server.js
getTrips: function getTrips(req, res, next){
var url = 'CTB-WS/rest/trips?from='+ req.tripinfo.fromCityId + '&to=' + req.tripinfo.toCityId + '&depart-date=' + req.tripinfo.departDate+ '&pax=1';
console.log(url);
rest.get(url).on('complete', function(trips) {
if (trips instanceof Error) {
console.log('Error:', trips.message);
} else {
console.log('trips'+ JSON.stringify(trips));
req.trips = JSON.stringify(trips);
next();
}
});
},
sendTrips: function sendTrips(req, res, next){
res.render('trips', {trips : req.trips});
}
請格式化您的問題。玉是空白敏感的。如果您無法找出降價來設置問題的格式,那麼空白敏感的模板語言可能不是您的最佳選擇。 –
對不起,是的,我已格式化它。 – jyoti