我写了一些函数,我调用了abApi.general.getUserById
函数,但是当我打印输出到$("#friend-requests-block")
我的name
变量时是空的。$("#friend-requests-block")
我知道这是javascript,我在回调中尝试 getUserById
,但后来我没有type
。我怎样才能解决这个问题?
for (var index in requests) {
var name = "";
var type = "";
if(requests[index].FriendRequestTypeId == 1) {
type = "private";
}
else {
type = "business";
}
abApi.general.getUserById(abEnvironment.sessionToken, requests[index].FromUserId, function(response2){
name = response2.Name;
});
$("#friend-requests-blocks").html($("#friend-requests-blocks").html() + "<div class=\"log-block\" id=\"friend-requests-log-"+requests[index].Id+"\"><a href=\"#\"><h2>"+ name + "("+ type +")</h2></a> <div class=\"friend-requests-buttons\" style=\"margin-top: 15px;\"> <a href=\"javascript:void(0)\" data-role=\"button\" style=\"margin: 0px 5px 0px 5px;\" onClick=\"abAction.approveFriendRequest("+requests[index].Id+", 1,"+requests[index].FromUserId+");\">Accept</a><a href=\"javascript:void(0)\"data-role=\"button\" style=\"margin: 0px 5px 0px 5px;\" onClick=\"abAction.approveFriendRequest("+requests[index].Id+", 0,"+requests[index].FromUserId+");\">Reject</a> <a class=\"button3\" href=\"javascript:void(0)\"data-role=\"button\" style=\"margin: 0px 5px 0px 5px;\" onClick=\"abAction.approveFriendRequest("+requests[index].Id+", 2,"+requests[index].FromUserId+");\">Later</a></div></div>");
}