【发布时间】:2020-08-20 10:22:01
【问题描述】:
我是 Svelte 的新手,在完成本教程后,我构建了这个组件 (https://reactjs.org/docs/thinking-in-react.html) 以便更好地理解它。在第 2 步中,ProductTable 类中有一个部分,在每个循环之后有以下语句
lastCategory = product.category;。有没有一种方法可以在每个块之后写一个语句?以下是我到目前为止的代码。
<script>
import ProductCategoryRow from './ProductCategoryRow.svelte';
import ProductRow from './ProductRow.svelte';
export let products;
let lastCategory = null;
</script>
<table>
<thead>
<tr>
<th>Name</th>
<th>Price</th>
</tr>
</thead>
<tbody>
{#each products as product}
{#if product.category !== lastCategory}
<ProductCategoryRow category={product.category} />
{/if}
<ProductRow product={product} />
<!-- lastCategory = product.category (?) -->
{/each}
</tbody>
</table>
抱歉我的英语不好,提前致谢:)
【问题讨论】:
标签: svelte