我正在编写chrome扩展,但发送响应不起作用.
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
if(!request.method){
return false;
}
if(request.method=='postList' && request.post_list){
// alert(1);
a_facebook_api.getPostFromDB(request.post_list, function(data){
alert(data);
sendResponse(data);
});
} else if(request.method=='postAdd' && request.post_data){
a_facebook_api.addPostToDB(request.post_data, function(data){
sendResponse(data);
});
}
return true;
}
);
chrome.runtime.sendMessage({method: "postList",post_list: post_list}, function(response) {
alert(response);
});
Run Code Online (Sandbox Code Playgroud)
功能警报数据有效.它为我提供了JSON格式的数据.但是,警报(响应)不显示任何消息.任何人都可以给我一些想法,为什么它不起作用?
先感谢您!
我正在做一个非常简单的功能,比如在 TextView 的末尾添加省略号。
我可以在 onMeasure()、onLayout() 和 OnGlobalLayoutListener() 调用中添加该功能。但我真的想知道通过实现相同的功能但在这三种不同的方法中有什么区别。选择这些不同的实现方式有什么偏好或优缺点吗?
谢谢