触发事件:点击:从Svelte数据表选择行

huangapple go评论74阅读模式
英文:

Dispatch event on:click:row--select from Svelte DataTable

问题

我正在尝试使用 https://carbon-components-svelte.onrender.com/components/DataTable 中的分派事件,具体是:on:click:row--select { selected: boolean; row: DataTableRow; },但我无法让它起作用。

我找到了自定义事件:

["click:row--select"]: CustomEvent<{
      selected: boolean;
      row: DataTableRow;
    }>;

但我不知道如何将其与我的代码集成:

addEventListener("click:row--select", handleSelect);

function handleSelect(e) {
   e.selected;
   e.Modal;
}
英文:

I am trying to use a dispatch event from https://carbon-components-svelte.onrender.com/components/DataTable namely the: on:click:row--select { selected: boolean; row: DataTableRow; } but i cannot get it to work

I found the custom event:

[&quot;click:row--select&quot;]: CustomEvent&lt;{
      selected: boolean;
      row: DataTableRow;
    }&gt;;

But i dont know how to integrate it with my code

addEventListener(&quot;click:row--select&quot;, handleSelect);

function handleSelect(e) {
   e.selected;
   e.Modal;
}

答案1

得分: 2

事件在Svelte中作为属性添加到组件上,以on:开头,所以在标记中的某个地方,你应该有:

<DataTable ... on:click:row--select={handleSelect}>
英文:

Events in Svelte are added on the component as attributes starting with on:, so somewhere in the markup you should have:

&lt;DataTable ... on:click:row--select={handleSelect}&gt;

huangapple
  • 本文由 发表于 2023年6月13日 17:41:31
  • 转载请务必保留本文链接:https://go.coder-hub.com/76463588.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定