我使用webflow在我的网站上使用google显示谷歌评论,目前,一切正常,但是显示5个评论,我想只显示2个
我已经有了一个代码来显示评论,但是我的代码中是否添加了只显示2个评论的代码?
<script>
var map = document.getElementById('google-places');
function initMap() {
var service = new google.maps.places.PlacesService(map);
service.getDetails({
placeId: 'xxxxxxxxxxxxxxxxx'
}, function (places, status) {
if (status === google.maps.places.PlacesServiceStatus.OK) {
reviewsArray = [];
reviewsArray.push(places.reviews);
for (var key in reviewsArray) {
var arr = reviewsArray[key];
for (i = 0; i < arr.length; i++) {
var review = arr[i];
var author = review.author_name;
var when = review.relative_time_description;
var comment = review.text;
var starNumber = review.rating;
var starPercentage = `${(starNumber / 5) * 100}%`;
console.log(starPercentage);
var profilePic = review.profile_photo_url;
// console.log(author + ', ' + when + ', ' + comment + ', ' + rating + ', ' + profilePic);document.getElementById('google-places').innerHTML += ` ${author}☆☆☆☆☆★★★★★
</div>
</div>
<div class="review-content-wrapper">
<div class="review-text">${comment}</div>
</div>
</div>
</div>
`
}
}
}
})
}
</script>
<!-- Replace XXX with your key that you created at https://console.cloud.google.com -->
<script async defer src="https://maps.googleapis.com/maps/api/js?key=xxxxxxxxxxxxxxxxx&libraries=places&callback=initMap">
</script>发布于 2019-01-30 17:59:58
似乎Google默认为5个评论(来源:Is it possible to get latest five google reviews from google places api?)。
你能不能只使用前两个而忽略最后三个?
发布于 2019-01-30 22:50:43
您应该能够在自己的代码中这样做;它不依赖于API;例如,如果您使用Jquery或PHP,您可以循环遍历数组,并且只显示索引0和1的评论,以便只显示两者,而忽略其余的内容。
https://stackoverflow.com/questions/54445786
复制相似问题