I would like to know how it is possible by code to convert a text to a tag. Suppose we have the following text:
[[{"value":2,"text":"Petrol Man","title":"Petrol Man","prefix":"@"}]]
how do I, via code convert it to the tagify classic graphical display?
EDIT:
I would convert this text [[{"value":2,"text":"Petrol Man","title":"Petrol Man","prefix":"@"}]]
to:
With the assumptions:
The tagify page has an example of adding new tags:
so you need to convert your json-string to an array of text values.
Use
JSON.parse
to convert to an object thendata[0].map(
to read each value out of the inner array - as the outer array (in the sample at least) is always a single dimension, you needdata[0]
to get to the inner array.Put together:
Unfortunately, the plugin uses
localStorage
without checking if it's available - and SO doesn't allow this, so no working snippet above, but here's a working fiddle: https://jsfiddle.net/50n7ckLe/