英文:
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:
["click:row--select"]: CustomEvent<{
selected: boolean;
row: DataTableRow;
}>;
But i dont know how to integrate it with my code
addEventListener("click:row--select", 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:
<DataTable ... on:click:row--select={handleSelect}>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论