我有一個Facebook feed聚合器,顯示我所有頁面的最新帖子。我一次只需要顯示10個帖子,然後點擊下面的「更多按鈕,顯示更多帖子,除了顯示每個可滾動頁面的每個帖子之外,其他所有功能都是功能性的,頁面加載非常緩慢,因爲數千帖子加載我已經完成了這個與我的Twitter的帖子,但由於某種原因不與Facebook。我已經張貼了Facebook和Twitter代碼,所以你可以比較,我需要幫助限制顯示的帖子數量。鏈接到該軟件的截圖。https://gyazo.com/d1c2363d553de2e267c3eddea5857fc3使用Javascript數組限制Facebook Feed信息的數量
的Facebook
this.morefacebookpagefeeds = function() {
var obj = vm.currentfacebookpaging();
var feedinfo = new Object();
feedinfo.facebookfeeds = new Array();
feedinfo.PagingList = new Array();
var item = 0;
obj.forEach(function (e, index, array) {
item++;
var parameters = e.next.split("?")[1];
var page = ko.utils.arrayFirst(vm.currentfeedModelArray(), function (i) {
return i.Id == e.PageId;
});
FB.api("/" + facebookuserid + "/feed?" + parameters, 'get', { access_token: facebookaccesstoken }, function (response) {
response.data.forEach(function (feed, index, array) {
var feedsdata = new Object();
feedsdata.Description = feed.description;
feedsdata.Picture = feed.picture;
feedsdata.Name = feed.name;
feedsdata.Link = feed.link;
feedsdata.Message = feed.message;
feedsdata.PageName = page.ProfileName != undefined ? page.ProfileName : "";
feedsdata.PostDate = moment(new Date(feed.created_time)).format('ddd MMM DD YYYY hh:MM a');
feedsdata.ProfileImage = page.ProfileImageUrl;
feedsdata.PageUrl = page.ProfileUrl != undefined ? page.ProfileUrl : "";
feedsdata.Id = page.ProfileId != undefined ? page.ProfileId : "";
feedinfo.facebookfeeds.push(feedsdata);
if (response.paging != null) {
feedsdata.Paging = new Object();
feedsdata.Paging.previous = response.paging.previous;
feedsdata.Paging.next = response.paging.next;
feedsdata.Paging.PageId = pageId;
}
feedinfo.PagingList.push(feedsdata.Paging);
});
if (item == array.length) {
feedinfo.facebookfeeds.forEach(function (item) {
vm.currentfeedModelArray.push(item);
});
feedinfo.PagingList.forEach(function (item) {
vm.currentfacebookpaging.push(item);
})
}
});
});
}
Twitter的
this.twitterfeeds = function (sinceid) {
if (sinceid) {
var sinceidvalue = vm.currenttwitterfeedModelArray()[vm.currenttwitterfeedModelArray().length - 1].Id;
}
ajaxExt({
type: "POST",
throbberPosition: { my: "center center", at: "center center", of: $(window), offset: "5 0" },
data: { sinceid: sinceidvalue },
url: baseUrl + 'Social/TwitterFeed',
showThrobber: true,
success: function (data) {
vm.feedModelArray.removeAll();
if (sinceidvalue == undefined || sinceidvalue == null) {
vm.currenttwitterfeedModelArray.removeAll();
}
if (data.Object == null || data.Object.length == 0) {
$('#loadmoretwitter_btn').css('display', 'none');
}
data.Object.forEach(function (item) {
vm.currenttwitterfeedModelArray.push(item);
});
}
});
}
您是否嘗試過添加限制參數:'FB.api(「/」+ facebookuserid +「/ feed?limit = 10)' –
謝謝並且是的,它限制了每個帳戶的帖子數量,但我管理接近60個帳戶,所以它加載所有60個帳戶,我希望它加載10個帳戶,然後打破並顯示「更多」按鈕 –