我有与Blogger Feed配合使用的“ favouritePosts” json回调函数:
<script type='text/javascript'>
//<![CDATA[
function favouritePosts(json) {
for (var i = 0; i < numposts; i++) {
var entry = json.feed.entry[i];
var posttitle = entry.title.$t;
var posturl;
postdate = entry.published.$t;
var post_id = i;
var postThumb = entry.media$thumbnail.url;
var authorname = entry.author[0].name.$t;
var author_img = entry.author[0].gd$image.src;
var author_uri = entry.author[0].uri.$t;
var label_category = entry.category[i].term;
var item = '<a class="listing-geodir-category" href="">'+label_category+'</a><a href="'+author_uri+'"></a><span class="avatar-tooltip">Added By <strong>'+authorname+'</strong></span></div><h3><a href="'+posturl+'">'+posttitle+'</a></h3><div class="geodir-category-options fl-wrap"></div></div>';
document.write(item);
}
}
//]]>
</script>
使用以下脚本调用
<script src='/feeds/posts/summary/-/Νέα%20Καταχώρηση?alt=json-in-script&callback=favouritePosts'/>
还有用于表格api的“ displayContent” json回调函数:
<script>
//<![CDATA[
function displayContent(json) {
var string = "";
var len = json.feed.entry.length;
for (var i=0; i<len; i++) {
var user = json.feed.entry[i].gsx$user.$t;
var comment = json.feed.entry[i].gsx$comment.$t;
var rating = json.feed.entry[i].gsx$rating.$t;
var date = json.feed.entry[i].gsx$date.$t;
string += '<div class="reviews-comments-item"><div class="reviews-comments-item-text"><h4><a href="#">' + user + '</a></h4><div class="listing-rating card-popup-rainingvis" data-starrating2="'+rating+'"></div><div class="clearfix"></div><p>"' + comment + '"</p><span class="reviews-comments-item-date"><i class="fas fa-calendar-check"></i>'+date+'</span></div></div>';
}
$(string).appendTo('div.reviews-comments-wrap');
}
//]]>
</script>
并用
调用<script src="https://spreadsheets.google.com/feeds/list/13zvQpUcOOwrFwJ6f9iiAKJSgrsdrYT_HqZNVR-BtwZI/od6/public/values?alt=json-in-script&callback=displayContent">;</script>
是否可以获取用于“ displayContent”表api json回调的变量并将其用于“ favouriteposts”回调函数?
也许带有一个承诺函数?