簡體   English   中英

javascript無法獲取對象屬性值

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM