我有如下的javascript对象:
var row = {
'fileAttribute' : {
'.\K\ar- #%i\.n/a': true,
'size': '2040',
'type' : 'pdf'
}
};
但是当我尝试获取row.fileAttribute ['。\ K \ ar-#%i.n / a']的值时,我得到的是undefined而不是true。
我知道我的属性名称包含特殊字符。 row.fileAttribute.hasOwnProperty('。\ K \ ar-#%i.n / a')返回false。
我试图通过_.values(row.fileAttribute ['。\ K \ ar-#%i.n / a'])提取这个属性值,但是我得到了空数组。
以下是此问题的示例:
http://jsfiddle.net/fvu2pqzz/8/
感谢您的帮助,谢谢!
答案 0 :(得分:0)
您需要使用bracket notation
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- #%i.n/a']);