gpt4 book ai didi

javascript - 仅在 ng-repeat 列表中显示唯一日期值

转载 作者:行者123 更新时间:2023-11-29 14:52:46 25 4
gpt4 key购买 nike

我有一个由 ng-repeat 生成的无序列表。在每个列表项中,我都有一个月份标题和一篇博文。

enter image description here

我只想显示每个月份名称的一个实例,但如果没有一些非常笨拙的 jQuery,我无法想出一个很好的方法来做到这一点。

有没有办法可以在 Angular 中检测到这个值并使用 ng-hide 只显示每种类型的第一个值?

最佳答案

也许这样的事情会有所帮助,前提是您的同月帖子是相邻的。如果不是,也许可以完全显示日期:

plnkr code example

基本上:

<li ng-repeat="post in model.blogPosts">
<span ng-show="model.blogPosts[$index - 1].date !== post.date">{{post.date}}</span>
<br>
<span>{{post.post}}</span>
</li>

编辑:

(抱歉默认的 ul li 样式,太丑了)

关于javascript - 仅在 ng-repeat 列表中显示唯一日期值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22883182/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com