json-editor
json-editor copied to clipboard
Dynamic array population based on another array
#Hi, I was wondering if it was possible to populate the data of a certain array with the data entered in another array. It would need to create a new item and not only be a template when we manually create an item.
groups: {
type: "array",
format: "tabs",
items: {
properties: {
content: {
type: "string"
}
}
}
},
events: {
type: "array",
format: "tabs",
items: {
properties: {
content: {
type: "string",
},
group: {
type: "string",
}
}
}
}
In this exemple, the property "group" from the items in the array "events" would populate the items in the array "groups". I want to know if it is possible and if yes, how to do it.
Thank you.
Based on your example, it's unclear what you'd need your watch target to be, but the following example does exactly what you're looking for:
"groups": {
"type": "array",
"format": "tabs",
"items": {
"type": "string",
"watch": {
"events-watch": "events"
},
"enumSource": "events-watch",
"enumValue": "{{item.group}}"
}
},
"events": {
"id": "events-id",
"type": "array",
"format": "tabs",
"items": {
"properties": {
"content": {
"type": "string"
},
"group": {
"type": "string"
}
}
}
}