Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/467.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 手柄-但是将一个数组中的所有元素作为一个元素的值推入另一个数组_Javascript_Json_Handlebars.js - Fatal编程技术网

Javascript 手柄-但是将一个数组中的所有元素作为一个元素的值推入另一个数组

Javascript 手柄-但是将一个数组中的所有元素作为一个元素的值推入另一个数组,javascript,json,handlebars.js,Javascript,Json,Handlebars.js,我的记录json文件中有一个元素,如下所示: "custitem_list": [ { "internalid": "1", "name": "FLAT AND DULL" }, { "internalid": "2", "name": "F

我的记录json文件中有一个元素,如下所示:

"custitem_list": [
    {
        "internalid": "1",
        "name": "FLAT AND DULL"
    },
    {
        "internalid": "2",
        "name": "FRIZZY"
    }
] 
现在我需要将列表名从记录中推送到另一个json记录中,作为属性元素中的选项值

"attributes": [
    {
        "id": 0,
        "name": "Custlist",
        "position": 0,
        "visible": true,
        "variation": false,
        "options": [
            {
                "FLAT AND DULL",
                "FRIZZY"
            }
        ]
    }
]
我尝试过以下方法,但都没有达到预期效果:

{
    "id": 0,
    "name": "Custlist",
    "position": 0,
    "visible": true,
    "variation": false,
    "options": [
        {
    {{#each record.custitem_list}}
    {{#if @index}}
    "{{{name}}}"
    ,{{/if}}
    {{/each}}
    }
    ]
}

{
    "id": 0,
    "name": "Custlist",
    "position": 0,
    "visible": true,
    "variation": false,
    "options": [
        {
            {{#each record.custitem_list}}
            {{#if @index}},{{/if}}
            {"name": "{{{name}}}"}
            {{/each}}
    ]
}

{
    "id": 0,
    "name": "Custlist",
    "position": 0,
    "visible": true,
    "variation": false,
    "options": [
        {
           {{#each record.custitem_list }}
           {{#if @index}},
           {{/if}}
           "{{{name}}}"
           {{/each}}
        }
    ]
}
谁能给我点启示吗

非常感谢

试试这个:

const names = obj.custitem_list.map(item => item.name);
obj2.attributes.options = names

下次请尽量给出没有错误的有效代码,并将其格式化以便于阅读。这是否回答了您的问题?