gpt4 book ai didi

javascript - Angular ng-选项 : iterate over a number array for displaying content of an other array but having index chosen in ng-model

转载 作者:行者123 更新时间:2023-11-30 11:51:16 25 4
gpt4 key购买 nike

我想要一个显示字符串数组项的下拉列表。我还希望将下拉列表中所选项目的索引作为 ng-model。

我知道我没有给出最好的描述,所以我写了我能做什么。

HTML

<select ng-model="chosenPropertyIndex"
ng-options="arrayProperties.PropertyNames[idx] for idx in [0,1,2,3,4,5]"
></select>

Controller

 $scope.chosenPropertyIndex = 0;

$scope.arrayProperties = [
"Property A",
"Property B",
"Property C",
"Property D",
"Property E",
"Property F"
];

请问您有没有办法做类似的事情?

最佳答案

试试这个:

<select ng-model="chosenPropertyIndex" ng-options="arrayProperties.indexOf(prop) as prop for prop in arrayProperties"></select>

http://jsfiddle.net/680x5grc/

关于javascript - Angular ng-选项 : iterate over a number array for displaying content of an other array but having index chosen in ng-model,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39386364/

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