參照大神建議
原本代碼
for (let i = 0; i < OperList.length; i++) { this.$refs.multipleTable.toggleRowSelection( OperList[i], true ) }
更新后代碼(
this.tableDataOper.find((item) => { return item.PATIENT_ID === row.PATIENT_ID }) 這行必須是唯一性
)
this.$nextTick(() => { if (this.tableDataOper.length > 0) { OperList.forEach((row) => { if (row !== null && row !== undefined) { this.$refs.multipleTable.toggleRowSelection( this.tableDataOper.find((item) => { return item.PATIENT_ID === row.PATIENT_ID }), true ) } }) } })
原因
$nextTick 是在下次 DOM 更新循環結束之后執行延遲回調,在修改數據之后使用 $nextTick,則可以在回調中獲取更新后的 DOM。
但這樣任然無法正常顯示
解決:這里通過從所有列表tableData中找到需要選中的項來幫助選中,直接使用選中列表來設置會出錯