我有一个简单的 ng-repeat 遍历对象数组。
ng-repeat 包含一个 ng-model 输入元素,我需要为其使用动态值作为数组索引。可能非常不清楚的解释所以这里是代码:
<div ng-repeat="property in current_data.object_subtype.object_property_type" ng-init="set_input_state()" class="input-group ng-scope disabled">
<span class="input-group-addon">{{property.name}}</span>
<input type="text" placeholder="{{property.name}}" ng-model="current_data.properties[getIndexFromId(current_data.properties, property.object_property_type_id)].value" class="form-control" disabled="disabled">
问题是输入保持为空。我已经测试了一些组合并发现它可以工作:
getIndexFromId(current_data.properties, property.object_property_type_id) == 0
current_data.properties[0].value
给出预期的输出
所以不知何故getIndexFromId(current_data.properties, property.object_property_type_id)
,Angular 不能很好地接受,或者我在某个地方犯了一个愚蠢的错误......
有谁知道这有什么问题?
谢谢!
[编辑]
这是所有这一切背后的数据样本:
{
"id": 1,
"name": "Robert Smith",
"object_subtype_id": 1,
"object_subtype": {
"id": 1,
"description": "Manager",
"object_property_type": [
{
"id": 1,
"description": "Phone number"
},
{
"id": 2,
"description": "Hair color"
},
{
"id": 3,
"description": "Nickname"
}
]
},
"properties": [
{
"id": 1,
"value": "819-583-4855",
"object_property_type_id": 1
},
{
"id": 2,
"value": "Mauves",
"object_property_type_id": 2
},
{
"id": 3,
"value": "Bob",
"object_property_type_id": 3
}
]
}