2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

LWCでカスタムデータ属性を扱うには

Posted at

前回書いたこちらのpost
https://qiita.com/geeorgey/items/ff2ab9503091366dfb7d
カスタムデータ属性を使うともっと便利になるという情報を頂いたので実際にやってみたらハマったので備忘録。

##どうやって使うのか
ここではハイパーリンクのクリックイベントを拾うことにする。

link.html
<a href={url} onclick={handleClick} data-opid={d.Opportunity__c}>{d.Opportunity__r.Name}</a>

js側でデータを受け取る場合

link_clicked.js

    handleClick_like_opportunity(event) {
        console.log(event)
        console.log(event.target);
        console.log(event.target.dataset.opid);
    }

event.target.dataset.opid
という形式で取得できる。
分かってしまえばかんたんなんですけど、知らないと永遠にたどり着けないという罠。

大感謝

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?