我正在编写一个与 gmail api 交互的 chrome 扩展(chrome 45 是我的版本),但在将消息从 background.js 发送到我的内容脚本时遇到问题。异步方面是问题所在。如何获取回调后发送的消息?
//---------in content script---------
chrome.runtime.sendMessage({ messageId: _id }, function (response) {
console.log('the respose.messagePayload is: ' + response.messagePayload);
});
//---------in background script---------
chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {
getMessage('me', request.messageId, function (payload) {
//i want to send my response here
//this executes and grabs the payload of data from the api, but isn't sending back the message to the content-script
sendResponse({ messagePayload: payload });
});
//this synchronous call sends a message to the …Run Code Online (Sandbox Code Playgroud) 我有一张桌子需要在报告中总结.这是我的样本表.
Orders
_____________________________________
CustomerId | CustomerName | OrderType
___________|______________|__________
1 | Adam | Shoe
1 | Adam | Shoe
1 | Adam | Shoe
1 | Adam | Hat
1 | Adam | Hat
2 | Bill | Shoe
2 | Bill | Hat
3 | Carl | Sock
3 | Carl | Hat
Run Code Online (Sandbox Code Playgroud)
我试图总结这个在没有循环的情况下传回我的viewmodel.这是我试图实现的结果.
CustomerName | Shoe | Hat | Sock | Total Orders
------------ | ---- | --- | ---- | ------------
Adam | 3 | 2 | …Run Code Online (Sandbox Code Playgroud)