在列表#newsfeedposts
上单击列表项时,我希望它将该项添加到本地存储。但是我当前的函数代码是here,它的作用是,无论点击什么项目,如果点击它,它将开始将列表中的所有项目添加到本地存储。我希望它只添加特定的列表元素。我一直在努力解决这个问题,并且一直没有为我做好准备:
以下是用于显示listview的html的内容
<ul data-role="listview" id="newsfeedposts" data-theme="a" data-overlay-theme="a" data-inline="true"data-inset="true"></ul>
请帮助
function showPosts() {
var queries = {
getpost: ("SELECT actor_id, created_time, likes, post_id, attachment, attachment.media, message FROM stream WHERE filter_key IN (SELECT filter_key FROM stream_filter WHERE uid=me() AND type='newsfeed') AND is_hidden = 0"),
users: ("SELECT id, name, url, pic FROM profile WHERE id IN (SELECT actor_id FROM #getpost)")
}
FB.api({
access_token: accessToken,
method: 'fql.multiquery',
queries: queries
}, function (response) {
var posts = response[0].fql_result_set;
var users = response[1].fql_result_set;
var user;
var name;
var id;
var markup = "";
var post;
var post_id;
var actor_id;
var message;
var attachment;
var attachmenthref;
var mediasrc;
for (var i = 0; i < posts.length; i++) {
post = posts[i];
post_id = post.post_id;
actor_id = post.actor_id;
message = post.message;
short_post = message.slice(0, 81);
attachment = post.attachment;
attachmenthref = post.attachment.href;
var created_time = post.time;
likes = post.likes.count;
for (var j = 0; j < users.length; j++) {
user = users[j];
name = user.name;
id = user.id;
if (posts[i].actor_id == users[j].id) {
if ((post.attachment.media != undefined) && (post.attachment.media[0].type == "photo")) {
var thumb_url = post.attachment.media[0].src;
var full_url = thumb_url.replace(/(\/[^/]*)s\.jpg$/, '/s720x720$1n.jpg');
markup += '<li><a href="#fbfullpostviewpage" id="addPostToLocalStorage" data-rel="dialog" data-transition="pop" data-overlay-theme="e" data-inline="true"><img src="' + thumb_url + '">' + '<h4>' + name + '</h4><p>' + 'posted this photo....</p><p>' + likes + '<img src="images/facebook-like-16.png"></p></a></li>';
addPostToLocalStorage(post);
$('#fbheader #headername').text(user.name);
//}
} else {
markup += '<li><a href="#fbfullpostviewpage" id="addPostToLocalStorage" data-rel="dialog" data-transition="pop" data-overlay-theme="e" data-inline="true"><img src="https://graph.facebook.com/' + id + '/picture">' + '<h4>' + name + '</h4><p>' + short_post + '....</p><p>' + likes + '<img src="images/facebook-like-16.png"></p></a></li>';
addPostToLocalStorage(post);
}
}
}
}
$('#newsfeedposts').append(markup);
$('#newsfeedposts').listview("refresh");
});
}
这是onclick功能
function addPostToLocalStorage(facebookPost) {
$('#newsfeedposts').on('click', function () {
localStorage.setItem("fbclickedPost", JSON.stringify(facebookPost));
console.log(facebookPost);
alert("this post was added to local storage");
});
}