gpt4 book ai didi

javascript - 如何按键对ng-options中的数组进行排序?

转载 作者:数据小太阳 更新时间:2023-10-29 04:05:13 25 4
gpt4 key购买 nike

有这样的数组:

month: Array[13]0: "M"1: "January"2: "February"3: "March"4: "April"5: "May"6: "June"7: "July"8: "August"9: "September"10: "October"11: "November"12: "December"

我愿意:

ng-options="key as value for (key, value) in data.month | orderBy:key"

但我得到未排序的选择列表。

最佳答案

要使用过滤器进行跟踪,请使用track by

标记

ng-options="key as value for (key, value) in data.month | orderBy:'key' track by key"

更新

这个 orderBy 永远不会工作,因为你有文字数组。您需要将此数组转换为类似 JSON 的对象,其结构类似于 [{id: 0, value: "M"}, {id: 1, value: "January"},......]

HTML

ng-options="item.id as item.value for items in data.month | orderBy:'id'"

Demo Plunkr

关于javascript - 如何按键对ng-options中的数组进行排序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30621053/

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