亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

刪除數組中的元素,怎么將刪除元素的id組成一個數組

刪除數組中的元素,怎么將刪除元素的id組成一個數組

皈依舞 2019-03-06 18:15:44
removeCost: function (item) {  let index = this.form.addReceiptsCostVOList.indexOf(item)    let ids = []  for (var i = 0; i < this.form.addReceiptsCostVOList.length; i++) {    ids.push(item.costId)    this.form.delCostIds = ids  }  if (index !== -1) {      this.form.addReceiptsCostVOList.splice(index, 1)    }      console.log('form', this.form)}想著在刪除一條數據后,獲取刪除數據的id,組成一個數組,怎么刪除多條數據,獲取多個id ,怎么設置循環條件
查看完整描述

3 回答

?
飲歌長嘯

TA貢獻1951條經驗 獲得超3個贊

removeCost: function (item) {

  let index = this.form.addReceiptsCostVOList.indexOf(item)

  let ids = []

  for (var i = 0; i < this.form.addReceiptsCostVOList.length; i++) {

    ids.push(item.costId)

  }

  this.form.delCostIds = ids

  for (let i = 0; i < ids.length; i++) {

    this.form.addReceiptsCostVOList.splice(ids.length - 1 - i, 1)

  }

  console.log('form', this.form)

}


查看完整回答
反對 回復 2019-03-21
?
繁華開滿天機

TA貢獻1816條經驗 獲得超4個贊

可以考慮 filter 過濾掉包含 item數組里的id的元素


查看完整回答
反對 回復 2019-03-21
?
慕碼人8056858

TA貢獻1803條經驗 獲得超6個贊

可以考慮使用閉包函數改造一下, 需要注意下this指向


removeCost: (() => {

  let ids = []

  this.form.delCostIds = ids

  return (item) => {

     let index = this.form.addReceiptsCostVOList.indexOf(item)

     if (index !== -1) {

         ids.push(item.costId)

         this.form.addReceiptsCostVOList.splice(index, 1)

     }

  }

})()


查看完整回答
反對 回復 2019-03-21
  • 3 回答
  • 0 關注
  • 743 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號