【发布时间】:2014-01-02 22:40:32
【问题描述】:
我需要这段代码的帮助:
FB.api("/me/friends?fields=id,name,birthday,picture, link", dojo.hitch(this, function(response) {
var birthdays = response.data; //list of friend objects from facebook
var currentMonth = new Date().getMonth() + 1;
var upcoming = [];
dojo.forEach(birthdays, function(item) {
if (item.birthday) {
var bday = item.birthday;
//if the birthday is after today
if (currentMonth <= bday.substr(0, 2) * 1 && new Date().getDate() <= new Date(bday).getDate()) {
upcoming.push(item);
}
}
});
//set the year to current year because of birth years being different.
var year = new Date().getFullYear();
upcoming = upcoming.sort(function(a, b) {
return new Date(a.birthday).setYear(year) - new Date(b.birthday).setYear(year);
});
console.log(upcoming);//console log here, but do whatever you want with the sorted friends
}));
该应用程序是关于祝即将到来的人们生日的。这段代码实际上在我的 index.html 文件的脚本标签中。脚本标签中包含登录 Facebook 所需的 fb.login 等。我对上面的代码感到困惑。我怎么能调用上面的代码,以便单独返回一个人的名字。然后调用他的图片,使其返回。然后是链接等,以便该人可以使用它通过 Facebook 上的这个应用程序祝福他的朋友。这是因为我想单独使用即将到来的人的生日、链接等。
【问题讨论】:
-
我想在上面的HTML代码中分别使用即将到来的人生日的id、姓名、生日、图片、链接。请告诉我它是怎么做的?
-
你的问题不是很清楚。 “分别”是什么意思?您已经拥有 forEach 循环中的所有字段。这会阻止您单独或一起使用字段?
-
谢谢您的回复。我的意思是,假设我将在即将到来的 12 月 17 日过生日。我会通过上面的代码得到它。/但现在假设另一个朋友在 17 日过生日。首先我想要你的名字,我会将它添加到 html 中的一个部门,它会出现在你图片旁边的框中。然后我会添加图片和链接,通过这些链接我会在你的墙上发布一些东西。但是我该怎么做呢?因为即将推出的盒子中有几个元素,我必须一次使用。
-
我必须一次得到你的每个名字、生日等,然后是其他人。现在我该如何完成并在我的 index.html 中执行它,一次一个?
标签: javascript html css text replace