Filtering an ng-repeat list based on a sub-object property

前端 未结 1 955
我寻月下人不归
我寻月下人不归 2020-12-29 02:45

jsfiddle http://jsfiddle.net/KfSBq/

By sub-object I mean that the objects I am displaying with ng-repeat all contain a list of objects within themselves, and I am lo

相关标签:
1条回答
  • 2020-12-29 03:03

    You are allowed to create new scope members inside the expressions.

    This lets you assign a filtered list to a new variable, which can be used throughout the local scope. With that, you can pass the length of the filtered list to ng-show:

    <body ng-app>
      <div ng-controller="Ctrl">
        <div class="daily" 
          ng-repeat="daily in dailies | orderBy:'-date' " 
          ng-show="filteredEntries.length"
        >
          {{ daily.date | date:'dd/MM/y' }}
          <div class="entry" 
            ng-repeat="entry in filteredEntries = (daily.entries | filter:{ category: 'B'})"
          >
            <span>{{ entry.category }}</span>, <span>{{ entry.note }}</span>
          </div>
        </div>
      </div>
    </body>
    

    FIDDLE

    Btw, nicely put question!

    0 讨论(0)
提交回复
热议问题