Following is my JSON Data validated using JSONLint:
[{
"text": "Products",
"data": {},
"children": [{
"text": "Fruit",
"data": {
"price": "",
"quantity": "",
"AddItem": "+",
"RemoveItem": "×"
},
"children": [{
"text": "Apple",
"data": {
"price": 0.1,
"quantity": 20,
"AddItem": "+",
"RemoveItem": "×"
}
}, {
"text": "Strawberry",
"data": {
"price": 0.15,
"quantity": 32,
"AddItem": "+",
"RemoveItem": "& #215"
}
}],
"state": {
"opened": false
}
}, {
"text": "Vegetables",
"data": {
"price": "",
"quantity": "",
"AddItem": "&# 43;",
"RemoveItem": "×"
},
"children": [{
"text": "Aubergine",
"data": {
"price": 0.5,
"quantity": 8,
"AddItem": "+",
"RemoveItem": "×"
}
}, {
"text": "Cauliflower",
"data": {
"price": 0.45,
"quantity": 18,
"AddItem": "+",
"RemoveItem": "×"
}
}, {
"text": "Potato",
"data": {
"price": 0.2,
"quantity": 38,
"AddItem": "+",
"RemoveItem": "×"
}
}]
}],
"state": {
"opened": false
}
}]
What I am looking for is to convert the value for the keys AddItem and RemoveItem to HTML buttons.
The above JSON will be used to render nodes in a jsTree plugin.
jsFiddle link where I will be using this json data. Basically, I want to replace my + and - sign with a button for the same
Does anyone has a work-around for this ?
Edit 1: I have read at a few places that adding HTML elements directly in your JSON data is not advisable as it can be used at a number of places in your code and each time it may have a different HTML for it. If someone has a better way to do it, that would be great.