gpt4 book ai didi

javascript - Angular,同步两个选择元素

转载 作者:行者123 更新时间:2023-12-03 10:14:06 25 4
gpt4 key购买 nike

我正在努力理解绑定(bind)和选择元素。我想要同步两个选择元素。看起来 ng-value="$index"应该是正确的方法,但它不起作用。

这些同步:

<select  ng-model="myVar1"><option value="{{n}}" ng-repeat="(n, o) in ['donny', 'felix', 'bob'] track by $index" >{{o}}</option></select>

{{o}}

但这些没有:

<select  ng-model="myVar2"><option ng-value="$index" ng-repeat="o in ['donny', 'felix', 'bob'] track by $index" >{{o}}</option></select> <select  ng-model="myVar2"> <option ng-value="$index" ng-repeat="o in ['donny', 'felix', 'bob'] track by $index" >{{o}}</option>   </select>

JSBIN: http://jsbin.com/dirugikice/1/edit?html,js,output

我错过了什么?

最佳答案

将 $index 括在括号中,例如 {$index}

<select  ng-model="myVar2"><option ng-value="{$index}" ng-repeat="o in ['donny', 'felix', 'bob'] track by $index" >{{o}}</option></select> <select  ng-model="myVar2"> <option ng-value="{$index}" ng-repeat="o in ['donny', 'felix', 'bob'] track by $index" >{{o}}</option>   </select>

http://jsbin.com/pubapigibi/1/edit

关于javascript - Angular,同步两个选择元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29966488/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com