【问题标题】:How to order Keyed each blocks in Svelte如何在 Svelte 中订购每个块的键控
【发布时间】:2021-09-28 10:16:13
【问题描述】:

我创建了一个包含用户列表的商店,我想使用不同的参数进行订购。

store.js

export const users = writable([
  {
    "id": 11,
    "name": "Kepler",
  },
  {
    "id": 13,
    "name": "Planck",
  },
// more users going in here

为此,我使用来自 Lodash 的 orderBy

案例 A。如果我不使用每个块的键控,那么 orderBy 将按预期工作。

App.svelte

{#each _.orderBy($users, [param], [order]) as user}
  <div>{user.id} {user.name}</div>
{/each}

但是,如果我删除或对我的商店进行一些特定更改,更新将无法正常工作。 A better explanation of what's happening in the Svelte's docs.

案例 B。如果我对每个块使用键控,则更新按预期工作,但不是 orderBy

App.svelte

{#each _.orderBy($users, [param], [order]) as user (user.id)}
    <div>{user.id} {user.name}</div>
{/each}

Here a Real Example on Svelte REPL.

访问上面的链接并单击按钮以在升序或降序之间切换。

可能我错过了关于每个块的键控,但想弄清楚 Svelte 专家如何解决这个问题。

【问题讨论】:

标签: javascript svelte svelte-3 svelte-component svelte-store


【解决方案1】:

这是 3.38 版中的一个错误。刚刚发布的 3.39 版本修复了这个问题。

【讨论】:

    猜你喜欢
    • 2020-10-11
    • 2021-02-09
    • 2020-02-01
    • 2015-09-23
    • 2021-10-03
    • 1970-01-01
    • 2019-10-19
    • 2012-01-29
    相关资源
    最近更新 更多