json-editor icon indicating copy to clipboard operation
json-editor copied to clipboard

Dynamic array population based on another array

Open AlexBenoit opened this issue 8 years ago • 1 comments

#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.

AlexBenoit avatar May 12 '17 18:05 AlexBenoit

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"
           }
        }
     }
  }

jschlumkoski avatar Jul 12 '17 14:07 jschlumkoski