我想要显示总数。博客中的帖子作者用ajax获取方法bellow是我的代码。
parseString
答案 0 :(得分:0)
制作一组作者["Ali","Bassam","Mohamed"]
,循环播放帖子并按作者过滤。使用max-results=9999
包含最多帖子数。
<div id='show'></div>
<script type="text/javascript">
$.ajax({
url: "/feeds/posts/default?alt=json-in-script&max-results=9999",
type: "get",
dataType: "jsonp",
success: function (data) {
var authors = ["Ali","Bassam","Mohamed"];
var postNum = new Array(authors.length).fill(0);
var result = "";
for (var i = 0; i < data.feed.entry.length; i++) {
for (var j = 0; j < authors.length; j++) {
if (data.feed.entry[i].author[0].name.$t == authors[j]) {
++postNum[j];
}
}
}
for (var i = 0; i < authors.length; i++) {
result += authors[i] + " : " + postNum[i] + "<br>";
}
document.getElementById('show').innerHTML = "<div class='totalposts'>" + result + "</div>";
}
});
</script>