我知道如何像这样在 Jsonnet 中进行数组理解,使用 for 循环,数组中的一个对象使用我定义的所有值循环:
local values = [
'foo',
'bar',
'foobar',
];
{
list: 'movies',
items: [
{
title: 'title',
language: 'english',
metadata: {
author: 'god',
value: v,
},
},
for v in values
],
}
输出:
{
"items": [
{
"language": "english",
"metadata": {
"author": "god",
"value": "foo"
},
"title": "title"
},
{
"language": "english",
"metadata": {
"author": "god",
"value": "bar"
},
"title": "title"
},
{
"language": "english",
"metadata": {
"author": "god",
"value": "foobar"
},
"title": "title"
}
],
"list": "movies"
}
我现在想对数组中的多个对象执行此操作,如下所示:
local values = [
'foor',
'bar',
'foorbar',
];
{
list: 'movies',
items: [
{
title: 'title',
language: 'english',
metadata: {
author: 'god',
value: v,
},
},
{
title: 'title2',
language: 'german',
metadata: {
author: 'devil',
value: v,
},
},
{
title: 'title3',
language: 'spanish',
metadata: {
author: 'chutulu',
value: v,
},
},
],
}
我需要做什么才能获得以下输出?所以三个对象中的每一个都得到三个值
{
"items": [
{
"language": "english",
"metadata": {
"author": "god",
"value": "foor"
},
"title": "title1"
},
{
"language": "english",
"metadata": {
"author": "god",
"value": "bar"
},
"title": "title1"
},
{
"language": "english",
"metadata": {
"author": "god",
"value": "foorbar"
},
"title": "title1"
}
{
"language": "german",
"metadata": {
"author": "devil",
"value": "foor"
},
"title": "title2"
},
{
"language": "german",
"metadata": {
"author": "devil",
"value": "bar"
},
"title": "title2"
},
{
"language": "german",
"metadata": {
"author": "devil",
"value": "foorbar"
},
"title": "title2"
}
{
"language": "spanish",
"metadata": {
"author": "chutulu",
"value": "foor"
},
"title": "title3"
},
{
"language": "spanish",
"metadata": {
"author": "chutulu",
"value": "bar"
},
"title": "title3"
},
{
"language": "spanish",
"metadata": {
"author": "chutulu",
"value": "foorbar"
},
"title": "title3"
}
],
"list": "movies"
}