刚接触 Angular,我在列标题上使用 Angular 的 orderBy
作为我之前文章中提到的代码片段: AngularJS orderby not working as expected
现在在我的 Controller 中,数组 vm.albums
仍将保持其原始顺序,因为它来自后端,而 orderBy 指令只是根据排序标准对 DOM 进行排序。我想知道每次从 DOM 重新排序后如何提取顶行?我需要根据表中第一行的位置来显示另一组详细信息。有什么线索吗?
最佳答案
您可以使用 javascript $filter('orderBy')(collection, expression, reverse, comparator)
中的过滤器.
vm.top = $filter('orderBy')(vm.albums, 'data.title')[0]
这将按 data.title
对相册
进行排序并提取顶行。
关于javascript - Angular orderBy 也对原始数组进行排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38361198/