一开始用concat进行拼接,总是不行,代码如下:

handleItemChange(e){
      console.log(e)  
      var itemList = e.detail.value
      itemList.forEach(item =>{
        var row = item.split(',')
        var list = []
        const obj = {name: row[1],value: row[0]}
        list.push(obj)
        this.setData({
          ids: this.data.ids.concat(row[0]),
          names: this.data.names.concat(row[1]),
          tagList: this.data.tagList.concat(list)
        })
})

后来用...展开再进行拼接就可以了:

handleItemChange(e){
      console.log(e)  
      var itemList = e.detail.value
      itemList.forEach(item =>{
        var row = item.split(',')
        var list = []
        const obj = {name: row[1],value: row[0]}
        list.push(obj)
        this.setData({
          ids: this.data.ids.concat(row[0]),
          names: this.data.names.concat(row[1]),
          tagList: [...this.data.tagList,...list]
        })
})

 

posted on 2021-01-06 19:06  周文豪  阅读(4330)  评论(1编辑  收藏  举报