你好,我想洗掉另一個陣列中的陣列索引,我解釋說我確定了三個決定,我有一個選擇將通過回圈陣列動態創建。
當我點擊選項是創建另一個。
reasons= [ [{one, two, three}] ] // first select
// when to click option ex: 'one' is push another array inside
reasons = [ [{one, two, three}], [{four, five,six}] ] // another select generate
我想當我在一個選擇中更改選項是在此之后洗掉所有陣列并創建一個新陣列等等
//if i cahnge to option 'two' is create array like this
reasons = [ [{one, two, three}], [{seven, heigth, nine}] ]
我的代碼方法changeReason不起作用是洗掉所有陣列
<template v-for="reason in reasons">
<select v-model="inputs" @change="changeReason">
<option
v-for="item in reason"
:key="item.id"
:value="item.value"
@click="returnNotSav(reason.id)"
>
reason
</option>
</select>
</template>
<script>
changeReason() {
let lastElement = this.reasons.length-1;
this.reasons.splice(lastElement, this.reasons.length);
}
</script>
uj5u.com熱心網友回復:
我認為您的問題實際上與系結有關。會試試這個:
this.reasons = [...this.reasons.splice(lastElement, this.reasons.length)];
uj5u.com熱心網友回復:
我正在解決我的問題謝謝大家的想法
let startIndex = this.reasons.findIndex(
(reason) => !!reason.find((item) => item.id === e.target.value)
);
this.reasons.splice(startIndex 1);
// is a parseInt()
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/397820.html
標籤:javascript Vue.js
下一篇:Vue.js螢屏大小回應能力
