我有我的角度JS觀點如下創建文本字段的字符串動態對象,在angularjs
<label class="control-label">Name:</label>
<input type="text" class="form-control" ng-model="config.name" />
<br />
<label class="control-label">versionSpecificApiConfig:</label>
<input type="text" class="form-control" ng-model="config.versionSpecificApiConfig" />
<br />
<label class="control-label">schemaUrl:</label>
<input type="text" class="form-control" ng-model="config.versionSpecificApiConfig.schemaUrl" />
<br />
我這樣做,因爲我需要配置對象的結構如下,
{
"name":"string",
"versionSpecificApiConfig":{
"string":{
"schemaUrl":"string"
}
}
}
但出現錯誤「無法在versionSpecificApiConfig字段中爲字符串設置屬性」。請幫助我創建這樣的結構(結構中的「字符串」是指特定文本框的相應值)。
你的對象結構是錯誤的。試試這個:{ 「名」: 「串」, 「versionSpecificApiConfig」:{ 「串」:{ 「schemaUrl」: 「串」 }} } 如何 – Jenny
將這項工作?輸入框是文本,但是'versionSpecificApiConfig'似乎是一個對象。 – Claies
@Jenny我怎麼才能達到這樣的對象結構,就像你說的那樣。請幫助 –