angularjs动态排序的JSON数据

时间:2022-06-12 20:39:12

I want to show below data in ascending order in select box.

我想在选择框中以升序显示以下数据。

Data is as under :-

数据如下: -

 [
  {
"value": "MKZ_2017_LCN2014",
"text": "林肯MKZ"
},
{
"value": "MKX_2016_LCN2014",
"text": "林肯MKX"
},
{
 "value": "MKC_presidential_LCN2014",
"text": "林肯总统系列MKC(Oasis)"
},
{
"value": "MKZ_2015_360used_LCN2014",
"text": "林肯MKZ(360)"
}
]

View code is :-

查看代码是: -

<select
  class="select-modal"
  ng-model="key3" 
  id="model-03-1"
  name="third-primary-model" 
  ng-options="nameplate.text for nameplate in thirdLevelDropDown track by nameplate.value"
  ng-change="getCarModel3(key3)"
   >
    <option value="">Select</option>
   </select>

I want to sort select box on the name of text.

我想对文本名称上的选择框进行排序。

Appreciate your help

感谢你的帮助

2 个解决方案

#1


0  

You can do this, Use | orderBy:'text'

你可以这样做,使用|排序依据:“文本”

  <select class="select-modal" ng-model="key3" id="model-03-1" name="third-primary-model" ng-options="nameplate.text for nameplate in thirdLevelDropDown | orderBy:'text'" ng-change="getCarModel3(key3)">
      <option value="">Select</option>
    </select>

DEMO

DEMO

#2


0  

This works for me.

这对我有用。

ng-options="nameplate.text for nameplate in (models | orderBy: 'text') track by nameplate.value"

#1


0  

You can do this, Use | orderBy:'text'

你可以这样做,使用|排序依据:“文本”

  <select class="select-modal" ng-model="key3" id="model-03-1" name="third-primary-model" ng-options="nameplate.text for nameplate in thirdLevelDropDown | orderBy:'text'" ng-change="getCarModel3(key3)">
      <option value="">Select</option>
    </select>

DEMO

DEMO

#2


0  

This works for me.

这对我有用。

ng-options="nameplate.text for nameplate in (models | orderBy: 'text') track by nameplate.value"