Angular 向现有数组中添加额外元素

Angular 向现有数组中添加额外元素,angular,Angular,实际数据: (3) [{…}, {…}, {…}] 0: {Capacity: "150", Series: "20", Make: "150", Model: "150", TowerHeight: "151", …} 1: {Capacity: "250", Series: "250", Make: "250", Mo

实际数据:

(3) [{…}, {…}, {…}]

   0: {Capacity: "150", Series: "20", Make: "150", Model: "150", TowerHeight: "151", …}

   1: {Capacity: "250", Series: "250", Make: "250", Model: "252", TowerHeight: "250", …}

   2: {Capacity: "151", Series: "21", Make: "151", Model: "151", TowerHeight: "152", …}
我想向这个数组添加一个额外的元素。请帮我拿这个箱子: 添加禁用:对于每个元素为true

我希望输出如下所示:

(3) [{…}, {…}, {…}]

   0: {Disabled: true, Capacity: "150", Series: "20", Make: "150", Model: "150", TowerHeight: "151", …}

   1: {Disabled: true, Capacity: "250", Series: "250", Make: "250", Model: "252", TowerHeight: "250", …}

   2: {Disabled: true, Capacity: "151", Series: "21", Make: "151", Model: "151", TowerHeight: "152", …}

希望这将帮助您:

const result = data.map(item => { return {...item, Disabled: true} })

在Angular 2+中,这应该很简单

对于Plunker解决方案

同时添加以下代码:

this.list = [
  {Capacity: "150", Series: "20", Make: "150", Model: "150", TowerHeight: "151"},
  {Capacity: "250", Series: "250", Make: "250", Model: "252", TowerHeight: "250"},
  {Capacity: "151", Series: "21", Make: "151", Model: "151", TowerHeight: "152"}
  ];


this.newlist = this.list.map(item => { return {Disabled: true, ...item} })
在下面添加输出:

旧名单:

新名单:


嗨,真的非常感谢。你的回答对我帮助很大。再次感谢…嗨。。。我还有一个问题。我从服务器得到如下响应:CreatedDate:2020-06-25T00:00:00.000Z,当我在HTML表格{{slot.CreatedDate | date:dd MM yyyy HH:MM}中显示数据时,该日期将显示为25-06-2020 05:30,但我需要从服务器收到的25-06-2020 00:00这样的输出。请向我推荐。谢谢…请参考这个:它会帮助你的。如果我的解决方案对您有帮助,请进行投票并检查是否已解决。谢谢你,你好。。。它仅用于格式化日期,但这里的问题是将接收时间添加到+5:30小时。如果你没有我的,请打+91-9333355552给我这个号码。我会向你解释的。谢谢你好,真的非常感谢。你的回答对我帮助很大。再次感谢…嗨。。。我还有一个问题。我从服务器得到如下响应:CreatedDate:2020-06-25T00:00:00.000Z,当我在HTML表格{{slot.CreatedDate | date:dd MM yyyy HH:MM}中显示数据时,该日期将显示为25-06-2020 05:30,但我需要从服务器收到的25-06-2020 00:00这样的输出。请向我推荐。谢谢
[
    {
        "Capacity": "150",
        "Series": "20",
        "Make": "150",
        "Model": "150",
        "TowerHeight": "151"
    },
    {
        "Capacity": "250",
        "Series": "250",
        "Make": "250",
        "Model": "252",
        "TowerHeight": "250"
    },
    {
        "Capacity": "151",
        "Series": "21",
        "Make": "151",
        "Model": "151",
        "TowerHeight": "152"
    }
]
[
    {
        "Disabled": true,
        "Capacity": "150",
        "Series": "20",
        "Make": "150",
        "Model": "150",
        "TowerHeight": "151"
    },
    {
        "Disabled": true,
        "Capacity": "250",
        "Series": "250",
        "Make": "250",
        "Model": "252",
        "TowerHeight": "250"
    },
    {
        "Disabled": true,
        "Capacity": "151",
        "Series": "21",
        "Make": "151",
        "Model": "151",
        "TowerHeight": "152"
    }
]