Javascript Object Property Undefined (GM_getValue(), GM_list
Javascript Object Property Undefined (GM_getValue(), GM_listValues(), Greasemonkey, Tampermonkey)
这可能
很简单,我不知道,但我正在尝试从 Tampermonkey(基本上是 Chrome 的 Greasemonkey)返回的对象创建一个字符串GM_getValue()
函数。
最终代码如下所示...
//Call GM_listValues() to get keys of all stored values
var keys = GM_listValues();
//Code to create CSV string out of first 10 records
var csvString = '';
for (j=0; j<10; ++j) {
var temp = GM_getValue(keys[j]);
csvString = csvString + '"' + temp.id + '"' + ",";
csvString = csvString + '"' + temp.time + '"' + ",";
csvString = csvString + '"' + temp.outcome + '"' + ",";
csvString = csvString + '"' + temp.condition + '"' + ",";
csvString = csvString + '"' + temp.wager + '"' + ",";
csvString = csvString + '"' + temp.chance + '"' + ",";
csvString = csvString + '"' + temp.profit + '"' + ",";
csvString = csvString + ''n';
}
//Code to download CSV
var a = document.createElement('a');
a.href = 'data:attachment/csv,' + encodeURIComponent(csvString);
a.target = '_blank';
a.download = 'myFile.csv';
document.body.appendChild(a);
a.click();
但是,结果是一堆未定义的字段。 调试时,我看到变量keys
被正确填充为键。 我看到变量temp
也获得了正确的数据。 当我做typeof temp
时,它说object
所以我认为它是一个对象。
当我console.log(temp)
时,它说json_val: {"id":"2132867232","time":"07:52","outcome":"84","condition":">1","wager":"0.50000m฿","chance":"98 %","profit":"+0.00520"}
json_val:
与为什么console.log(temp.id)
退货undefined
有关吗?
我也尝试了temp["id"]
,也得到了未定义。
任何帮助都非常感谢。 提前谢谢。
确保在
文件顶部包含授权。
// ==UserScript==
// @grant GM_getValue
// @grant GM_listValues
// ==/UserScript==
相关文章:
- missing ) after argument list DATEDIF
- 在List.js中使用非英语字符
- 从Iframe检索List并使用List更新父帧
- Div and ul list side by side
- 无法反序列化 java.util.List 的实例VALUE_STRING
- 返回List<字符串>Jquery中的from JSON调用具有未定义的长度
- 传递List
作为Javascript函数的参数 - jqGrid - TypeError: “#List”.jqGrid 不是一个函数
- 如何使用 List.js 正确刷新列表
- Javascript: parse json to list
- List.JS 在通过 Chrome 扩展程序注入时不起作用
- 使list.js和react.js协同工作
- Angular Grocery List-删除单个项目
- Insert dynamically created list items in <ol> with jqu
- 几秒钟后自动关闭ul.parsley-error-list
- 使用GM-xmlhttpRequest而不是iframe来显示来自外部页面的相关信息
- SyntaxError: missing ) after argument list in fire bug
- javascript SyntaxError: missing ) after argument list
- While为List值在CSS选择器中循环迭代
- List.js对很长的项目排序不正确