无法使用 vue.js 将数组复制到数组 [英] Unable to copy an array to an array using vue.js

查看:28
本文介绍了无法使用 vue.js 将数组复制到数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用 vuetify 选择组件的多选择框.我正在获取所选项目的数组,并且我想将状态合并为所选项目的真实状态,例如 [ { "ward": 1, "status": true }, { "ward": 2, ";状态":真}]我正在尝试将选定的数组项复制到另一个数组,但未能成功.在控制台中,我得到了 selectedFruits 如下.

I have a multiple selectbox using vuetify select component. I'm getting array of selected items and I want to merge status as true of selected items like [ { "ward": 1, "status": true }, { "ward": 2, "status": true} ] I'm trying to copy selected items of array to another array but couldn't succeed. In console, I got selectedFruits as below.

 methods: {
    save() {
      console.log(this.selectedFruits);
      debugger;    
      this.selectedIndex.push({ ward: this.selectedFruits, status: true });
      console.log(this.list);
    },

推荐答案

你可以试试这个

save(){
  this.list = []
  this.selectedFruits.forEach(e => {
      this.list.push({ ward: e, status: true });
    });
    console.log(this.list)
}

这篇关于无法使用 vue.js 将数组复制到数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆