我一直试图用tailwind 手风琴展示一系列帖子,但效果并不像预期的那样好.当创建帖子时,手风琴将显示标题,但不会展开以显示帖子的内容.我还更改了data-accordion-Target的属性,以使用"ngfor:index as I"动态定位Body.此外,我不确定将 struct 指令放在哪里,因为它有点像是显示了两个单独的手风琴.
<div id="accordion-collapse" data-accordion="collapse">
<div *ngFor="let post of posts; index as i">
<h2 id="accordion-collapse-heading-1">
<button type="button"
class="flex items-center justify-between w-full p-5 font-medium rtl:text-right text-gray-500 border border-b-0 border-gray-200 rounded-t-xl focus:ring-4 focus:ring-gray-200 dark:focus:ring-gray-800 dark:border-gray-700 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-800 gap-3"
attr.data-accordion-target="#accordion-collapse-body-{{i}}" aria-expanded="true"
attr.aria-controls="accordion-collapse-body-{{i}}">
<span>{{post.title}}</span>
<svg data-accordion-icon class="w-3 h-3 rotate-180 shrink-0" aria-hidden="true"
xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 10 6">
<path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
d="M9 5 5 1 1 5" />
</svg>
</button>
</h2>
<div id="accordion-collapse-body-{{i}}" class="hidden" attr.aria-labelledby="accordion-collapse-heading-{{i}}">
<div class="p-5 border border-b-0 border-gray-200 dark:border-gray-700 dark:bg-gray-900">
<p class="mb-2 text-gray-500 dark:text-gray-400">{{post.content}}</p>
</div>
</div>
</div>
</div>