循环创建多个上下文菜单
我有一大块代码:
for (game in settings_object.games)
{
chrome.contextMenus.create({
"title": "Add thread("+request.thread+") to game: "+game,
"contexts":["page"],
"onclick": function () {addThreadToGame(game,request.thread)}
});
}
生成一个上下文菜单,如下所示:
- 将线程(1234)添加到游戏:游戏一的 ID
- 将线程(1234)添加到游戏:游戏二的 ID
- 将线程(1234)添加到游戏:游戏三的 ID
目的是当用户点击“将线程 (1234) 添加到游戏:游戏一的 ID” 时,然后 addThreadToGame("游戏一的 ID", "1234") 执行...不幸的是,addThreadToGame 似乎总是被触发为 addThreadToGame ("ID of Game Three", "1234") 因为值被传递给函数始终是它在运行时而不是菜单生成时的最后一个值...我错过了什么?
I have a chunk of code:
for (game in settings_object.games)
{
chrome.contextMenus.create({
"title": "Add thread("+request.thread+") to game: "+game,
"contexts":["page"],
"onclick": function () {addThreadToGame(game,request.thread)}
});
}
That generates a context menue like:
- Add thread (1234) to game: ID of Game One
- Add thread (1234) to game: ID of Game Two
- Add thread (1234) to game: ID of Game Three
and the intention is for when the user clicks on "Add thread (1234) to game: ID of Game One" then addThreadToGame("ID of Game One", "1234") get's executed... unfortunately it seems like addThreadToGame is always triggered as addThreadToGame ("ID of Game Three", "1234") because the value being passed to the function is always the last value it has at run time not menu generation time... what am I missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
得出了答案:
调整我在 chrome 扩展中的选择和站点搜索中找到的代码后
Worked out the answer:
after adapting the code I found in selection and site search in chrome extension