[英]javascript can't get object property value
我有如下的javascript对象:
var row = {
'fileAttribute' : {
'.\K\ar- #%i\.n/a': true,
'size': '2040',
'type' : 'pdf'
}
};
但是,当我尝试获取row.fileAttribute ['。\\ K \\ ar-#%in / a']的值时,我得到的是undefined而不是true。
我知道这是因为我的财产名称包含特殊字符。 row.fileAttribute.hasOwnProperty('。\\ K \\ ar-#%in / a')返回false。
我试图通过_.values(row.fileAttribute ['。\\ K \\ ar-#%in / a'])提取此属性值,但是我得到了一个空数组。
这是此问题的示例:
http://jsfiddle.net/fvu2pqzz/8/
感谢您的帮助,谢谢!
您需要使用括号符号
console.info(row.entity.fileAttribute['.Kar- #%i.n/a']);
var row = { 'entity' : { 'fileAttribute' : { '.\\K\\ar- #%i\\.n/a': true, 'size': '20', 'qty' : '50' }, 'part2' : { 'name': 'Part 2', 'size': '15', 'qty' : '60' } } }; console.info(row.entity.fileAttribute['.Kar- #%in/a']);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.