I have a list of events that I display using ng-repeat. From each event, I need to access the previous and next event for HTML display reasons. When I don't use filters, this works well using
我有一个使用ng-repeat显示的事件列表。从每个事件中,我需要访问上一个和下一个事件,以了解HTML显示原因。当我不使用过滤器时,这很适合使用
events[$index - 1]
However, if I filter and re-order the events using
但是,如果我使用过滤和重新排序事件
event in events | myMinDate: 'start':config.now | orderBy: 'start'
I cannot use this techique, as the events array still refers to the original (unfiltered, unsorted) data structure. It's unfortunate there is no data array of the filtered data or something like $previous and $next.
我不能使用这种技术,因为事件数组仍然引用原始(未过滤,未排序)数据结构。不幸的是,没有过滤数据的数据数组或类似$ previous和$ next的数据。
Any ideas how this can be achieved without touching the actual events array?
任何想法如何在不触及实际事件数组的情况下实现这一目标?
1 个解决方案
#1
16
You can save the results of the filter into a new variable:
您可以将过滤器的结果保存到新变量中:
event in filteredEvents = (events | myMinDate: 'start':config.now | orderBy: 'start')
Then:
然后:
filteredEvents[$index - 1]
#1
16
You can save the results of the filter into a new variable:
您可以将过滤器的结果保存到新变量中:
event in filteredEvents = (events | myMinDate: 'start':config.now | orderBy: 'start')
Then:
然后:
filteredEvents[$index - 1]