我的函数将从外部api接收一个数组对象,我可以将其转换为JSON格式。假设这是我的JSON对象的样子:
{
"id": 99,
"title": null,
"author": "user",
"content": "content",
"url": "https://stackoverflow.comt"
},
{
"id": 100,
"title": null,
"author": "user",
"content": "content",
"url": "https://www.google.com"
}
从上面接收到的数据中分离出特定的键值对后,它的样子是这样的:
{"url":"https://www.google.com/"}
这个过程是异步调用的,当我点击扩展时触发,我可以在控制台中看到。现在在我的模板popup.html中。
<td>
<input type="text" name="url" id="url">
<input type="hidden" name="content" id="content" value="content" />
</td>
popup.js
chrome.tabs.query({active: true, currentWindow: true },
function callback(tabs) {
var currentTab = tabs[0]; // there will be only one in this array
$("#url").val(currentTab.url);
});
它从标签中获取当前URL并将其发送到post.js,其中进行后端操作。 现在我想检查URL数据并将其与JSON对象中的每个URL进行比较
我是Jquery / Javascript的新手。我尝试将此值与JSON中的每个值进行比较,但没有用。