初始渲染時數據顯示正常,這意味着如果我有自定義字段的數據,則這些值將顯示在HTML上。未綁定到對象數組的文本輸入
問題是,當我更改自定義字段的值時,更改沒有附加回對象,換句話說,出現某種原因,綁定只是一種方式。
我有以下對象:
{
"_id" : BinData(3, "6aUPCzvqTUuzZWlWRJCdPQ=="),
"name" : "MyObject",
"customFields" : [
{
"_id" : BinData(3, "ksRiQNZnuE2BKFpjbQEQaQ=="),
"name" : "Field 1",
"order" : NumberInt(1),
"type" : "string",
"isMultiValue" : false,
"values" : [
"11111"
]
},
{
"_id" : BinData(3, "S9bSzoqy5EafPP0NEdbfCw=="),
"name" : "Field 2",
"order" : NumberInt(2),
"type" : "string",
"isMultiValue" : false,
"values" : [
""
]
}
]
}
我有以下的HTML綁定到它:
<div ng-repeat="customField in customer.customFields">
<p>
{{customField.name}}:
</p>
<p ng-repeat="customFieldValue in customField.values">
<input type="text" class="form-control" ng-model="customFieldValue" />
</p>
</div>
更新: 後從@ngLover建議我得到的結合在正常工作這種情況下:
這是新對象:
{
"_id" : BinData(3, "FKibZl5WDk2jprg1gY5KAQ=="),
"name" : "MyObject",
"customFields" : [
{
"_id" : BinData(3, "3HUUHy1FMUaxD41JcuYqQw=="),
"name" : "Field 1",
"order" : NumberInt(1),
"type" : "string",
"isMultiValue" : false,
"values" : [
{
"value" : "Data 1"
}
]
},
{
"_id" : BinData(3, "2t0oiy5LukSSuPR9XYKwcA=="),
"name" : "Field 2",
"order" : NumberInt(2),
"type" : "string",
"isMultiValue" : false,
"values" : [
{
"value" : "Data 2"
}
]
}
]
}
新的HTML:
<div ng-repeat="customField in customer.customFields">
<p>
{{customField.name}}:
</p>
<p ng-repeat="customFieldValue in customField.values">
<input type="text" class="form-control" ng-model="customFieldValue.value" >
</p>
</div>
你可以請你創建你的代碼的小提琴。 – Mitul
customField.values是一個數組,使其像一個簡單的var類似於:11111 – ngLover
@ngLover我將customField.values更改爲自定義對象,現在綁定工作正常。 – CodeMilian