前端老生

cytoscape.js/documentation/md/collection/scratch.md

scratch()方法说明

cytoscape.js/documentation/md/collection/scratch.md

此函数主要用于存储临时的数据(像非JSON数据)。 扩展---如布局,渲染器等---使用在其命名空间上命名的ele.scratch()。 例如,名为foo的扩展名将使用命名空间'foo'。

如果要将此功能用于自己的应用程序级数据,则可以在下划线之前为命名空间添加前缀,以免与扩展名发生冲突。 例如,在您的应用程序中使用ele.scratch('_ foo')可以避免foo命名发生的冲突。

该函数主要是将非JSON数据与元素关联。 尽管ele.data()包含ele.json(),但ele.scratch()不包含于ele.json()。 这使得临时临时存储不可序列化的数据变得很容易。

原文:

This function is useful for storing temporary, possibly non-JSON data. Extensions --- like layouts, renderers, and so on --- use ele.scratch() namespaced on their registered name. For example, an extension named foo would use the namespace 'foo'.

If you want to use this function for your own app-level data, you can prefix the namespaces you use by underscore to avoid collisions with extensions. For example, using ele.scratch('_foo') in your app will avoid collisions with an extension named foo.

This function is useful for associating non-JSON data to an element. Whereas data stored via ele.data() is included by ele.json(), data stored by ele.scratch() is not. This makes it easy to temporarily store unserialisable data.