json-editor
json-editor copied to clipboard
Is it possible to create "template" field in array of elements?
I have some schema like this:
schema: {
title: "TOPICS AND RULES",
disable_edit_json: true,
disable_properties: true,
disable_array_reorder: true,
disable_collapse: true,
type: "array",
name: "some name",
format: "tabs",
items: {
type: "object",
format: "grid",
uniqueItems: true,
title: "RULE",
properties: {
path: {
title: "ROOT Topic",
type: "string",
minLength: 4,
defaut: "/hepek/"
},
type: {
type: "string",
enum: ["rc-switch", "ir-switch"],
default: "rc-switch"
},
name: {
type: "string"
},
message: {
type: "string"
},
code: {
type: "string"
},
path_would_be: {
type: "string",
description: "command for mqtt",
template: "{{path}}",
watch: {
path: 'item.path',
}
}
}
},
"default": [{
path: "/somepath/",
name: "somename",
code: "somecode"
}],
}
But i can't figure out if there is a way for "path_would_be" to be combination of previous values in same node?
Any idea???
You need to pass the index to your watch statement. For example, if you are going to watch the first element in the item for the path, you should use:
watch: {
path: 'item.0.path',
}
As a follow up, is there anyway to reference the particular item in the array that's doing the watching?
i.e.
watch: {
path: 'item.i.path'
}