我有一個多級對象,其中定義了不同的對象。其中一些屬性的「葉子」是默認值,並且包含一個默認值。探索並獲取多級對象的屬性
我需要在javascript中構造另一個對象,具有與葉子相同的「路徑」,但默認值爲屬性的值。
對於同一個「樓層」上的所有對象都可以,對象上有簡單對象和hasOwnProperty。但在這裏,在我看來,我需要探索對象的時間更長,而且我不知道如何解決對象,因爲我不能使用像object [iter1.iter2.iter3 ...] 。 我需要一提的是我工作的一個服務現在服務器在尤里卡版本,所以它僅支持ECMAScript的3
有一個例子:
OBJET我需要處理( JSON編碼):
"schema": {"properties": { "videoCapability": { "default": "1", "type": [ "string" ], "choices": [ { "value": "0", "title": "Disabled" }, { "value": "1", "title": "Enabled" } ], }, "ice": { "properties": { "iceCapability": { "default": "1", "type": [ "string" ], "choices": [ { "value": "0", "title": "Disabled" }, { "value": "1", "title": "Enabled" } ], "name": "iceCapability"," }, "defaultcandidatetype": { "default": "0", "type": [ "string" ], "choices": [ { "value": "0", "title": "Host" }, { "value": "1", "title": "Server Reflexive" }, { "value": "2", "title": "Relayed" } ], }, etc.
對象我需要建立:
"config": { config.properties.videoCapability = "1" config.properties.ice.properties.iceCapability = "1" config.properties.ice.properties.defaultcandidatetype = "0" }
等
如果你想知道爲什麼我要做到這一點,它是第一個對象是JSON從遠程服務器retreived。在將這個json編碼到一個對象後,我需要修改一些屬性,但不是全部。我需要將對象(已解碼)發送回遠端服務器。
您的「我需要構建的對象」是無效的語法。你的意思是'{「config.properties.videoCapability」:「1」}'? –