【问题标题】:Angular sort by name incorrectAngular 按名称排序不正确
【发布时间】:2016-06-21 03:13:13
【问题描述】:

我不明白为什么在 ng-repeat 中按名称排序是不正确的。订单一开始是正确的,但随后 Holland 的订单是错误的:

<div class="row">
  <div ng-if="region.checked && region.countCountries > 0" ng-repeat="region in vm.selectedRegions track by region.id" class="col-xs-12 col-sm-12 col-md-12 col-lg-12 padding-left-0">
    <strong class="region-title">{{ 'locales.region.' + region.name | translate }}</strong>
    <div class="row">
      <div ng-if="($index == 0)" ng-repeat="country in region.countries track by $index" class="col-xs-6 col-sm-6 col-md-6 col-lg-6 padding-left-0">
        <div ng-if="country.selected && ($index < region.countries.length/2)" ng-repeat="country in region.countries | orderBy: 'name' track by country.id">
          <span class="fa fa-circle"></span>
          <span translate="{{ 'locales.country.' + country.isoCode | translate }}"></span>
        </div>
      </div>
      <div ng-if="($index == vm.Math.ceil(region.countries.length/2))" ng-repeat="country in region.countries track by $index" class="col-xs-6 col-sm-6 col-md-6 col-lg-6 padding-left-0">
        <div ng-if="country.selected && ($index >= region.countries.length/2)" ng-repeat="country in region.countries | orderBy: 'name' track by country.id">
          <span class="fa fa-circle"></span>
          <span translate="{{ 'locales.country.' + country.isoCode | translate }}"></span>
        </div>
      </div>
    </div>
  </div>
</div>

奥地利 比利时 保加利亚 丹麦 芬兰 法国 德国 希腊 匈牙利 爱尔兰 以色列 意大利 荷兰 挪威 波兰 葡萄牙 罗马尼亚 西班牙 瑞典 瑞士 火鸡 英国

【问题讨论】:

  • 可能名称存储为“荷兰”,然后将isoCode 翻译为“荷兰”?

标签: angularjs ng-repeat angularjs-orderby


【解决方案1】:

也许“奥地利比利时保加利亚丹麦芬兰法国德国希腊匈牙利爱尔兰以色列意大利”在您的第一个 ng-repeat 中,而“荷兰挪威波兰葡萄牙罗马尼亚西班牙瑞典瑞士土耳其英国”在第二个 ng-repeat 中。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-02-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-21
    • 2018-03-26
    • 1970-01-01
    相关资源
    最近更新 更多