From all the Facebook Javascript SDK, deleting an action is the easiest to learn. But it is the most difficult to implement. Fortunately, with jquery, we can reduce this difficulty. Basically, if you want to remove an action, what you have to do is
if(response){
$('#activities ul #'+getIdArticle).remove();
}
});
Where, getIDArticle is the ID of the action to delete. The biggest problem is, in removing an action you have to know the ID of the action appropriately. To reduce this problem, you can use the trick of my recommendation. That is, get a list of actions using the li tags. Where each li tag must contain the ID with the ID of the action. Consider the following example
<ul>
<li id = ‘idaction1’>action 1</li>
<li id = ‘idaction2’>action 2</li>
<li id = ‘idaction3’>action 3</li>
</ul>
From here, you can select an action to be removed properly. You can use remove() to remove an action from the list and attr('id') to get the ID of the action. So you need a good cooperation between the function of getting and deleting actions. Look at the following code example
FB.api('/me/news.reads?access_token='+token, 'get', function(response){
mehtml = '<ul>';
if(response.data.length == 0){
mehtml += '<li>You are have no activities right know, turn on social share.</li>';
}else{
if(response.data.length > 5) response.data.length = 5;
for(var i = 0; i < response.data.length; i++){
mehtml += '<li id="'+response.data[i].id+'">';
mehtml += "You had read " + '<a href="'+response.data[i].data.article.url+'" target="_blank">' + response.data[i].data.article.title + '</a>' + " on " + response.data[i].start_time;
mehtml += '<div id="'+response.data[i].id+'">delete</div>';
mehtml += '</li>';
}
}
mehtml += '</ul>';
$('#activities ul li').append(mehtml);
$('#activities ul li').hover(
function(){
$('ul', this).slideDown(100);
},
function(){
$('ul', this).slideUp(100);
}
);
var getIdArticle = "";
$('#activities ul li div').click(function(){
getIdArticle = $(this).attr('id');
FB.api('/'+getIdArticle,'delete',function(response){
if(response){
$('#activities ul #'+getIdArticle).remove();
}
});
});
});
If you use other type of action, you can implement similar step like above. But don't forget to always check JSON output of your action with Graph API Explorer (https://developers.facebook.com/tools/explorer).
kunjungan balik sis, blognya keren dan postingaannya bagus2..
ReplyDeletethanks
Ok... sy pasti datang
ReplyDelete