0
0

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 5 years have passed since last update.

HTML要素のデータの保存方法

Posted at

Abstract

HTMLドキュメントやJavaScript上で作成したHTML要素のデータ(各属性値など)をファイルやデータベースに保存する方法について覚書を記す。

方法

・WeakMapを使う

WeakMapとは、オブジェクト作成用のオブジェクトである。
普通のオブジェクトはkeyに文字列しか使えないのに対し、WeakMapで作ったオブジェクトにはオブジェクトをkeyに使える。

あるHTML要素-例えばdiv要素-のデータを保存するにはkeyに以下のようなオブジェクトを作って指定すればよい:

まず、WeakMapでオブジェクトmyDivを作成する
→keyに「DOMのdiv要素オブジェクト」を設定する。

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?