gpt4 book ai didi

javascript - 将项目放入列表框中 - 在 Angularjs 中说 "opt as opt for opt in months"是什么意思?

转载 作者:行者123 更新时间:2023-12-01 00:08:04 25 4
gpt4 key购买 nike

https://angularjsaz.blogspot.com/2015/09/tutorial-28-angularjs-listbox-example.html

这表明:

<select style="width: 100%;" size="7" ng-model="currentItems" multiple  
ng-multiple="true"
ng-options="opt as opt for opt in months">
</select>

这有效。我想了解此声明的作用:选择为选择几个月内选择

我还知道ng-repeat需要汽车中的汽车。为什么我不能在这里使用这样的东西?

就我而言,汽车是:

cars = [
{make: 'Mazda', model: 'Miata', year: 2001},
{make: 'Toyota', model: 'Prius', year: 2013},
]

就他们而言,月份是:

months = ['January','February','March','April']

最佳答案

According to the documentation ,用于迭代数组数据源(如您的情况)的 ng-options 遵循以下模式:

select as label for value in array

地点:

array: an expression which evaluates to an array / object to iterate over.

value: local variable which will refer to each item in the array or each property value of object during iteration.

label: The result of this expression will be the label for element. The expression will most likely refer to the value variable (e.g. value.propertyName).

select: The result of this expression will be bound to the model of the parent element. If not specified, select expression will default to value.

这主要用于将对象数组显示为选择列表中的选项,您希望在其中迭代对象、标签以及绑定(bind)到 ng-model 指令的值是 3 种不同的东西。在你的例子中,它们只是字符串,所以它基本上就是说 stringSelectValue as stringLabel for stringItem in stringArray

您可以通过说 ng-options="month formonth inmonths" 来简化此示例。如果未提供选择值,它也会使用标签值作为选择值。

关于javascript - 将项目放入列表框中 - 在 Angularjs 中说 "opt as opt for opt in months"是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60236487/

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