我使用 ng-options 创建了普通选择框。我在对象中有 value
属性和 members
数组
$scope.currentprop = {
name : "graphFillDirection",
members : [{
name : "ttb",
caption : "Top to Bottom",
}, {
name : "btt",
caption : "Bottom to Top"
}, {
name : "ltr",
caption : "Left to Right"
},{
name : "rtl",
caption : "Right to Left"
}],
value : "ttb"
}
所以我用members.name
创建了下拉值。这是我的html
<select ng-model="currentprop.value" ng-options="value.name for (key , value) in currentprop.members"></select>
问题
我迭代成员数组,并使用value
属性检查name
。因此,如果 members.name
等于 value
那么我应该将检查的索引值传递给 ng-model。
在普通的 javascript 中,我们曾经喜欢这样 currentprop.members.name.indexOf(currentprop.value)
。所以这就是我需要分配给 ng-model 的内容。
目前我在 ng-model 中使用 currentprop.value 。在这个地方我应该使用检查值的索引值。
我不知道如何实现它。请帮我。提前致谢。 Plnkr这里
最佳答案
尝试ng-selected
<select ng-model="currentprop.value"
ng-options="value.name as value.name for (key,value) in currentprop.members"
ng-selected="{{currentprop.value == value.name}}">
</select>
关于javascript - 使用 ng-options value 检查该值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37595477/