我正在与BootstrapVue
合作。首先,我想简短地解释一下我的代码:
我有一个v-for输入,我可以用b-button -> addElement
创建任意次数的输入。或者我可以从我的b-dropdown
中选择一个item
-在那里我检查我选择的长度,并将我的arrayLength
的数量作为我的输入。
→如选择数组=[' 1111 ',' 2222 ',' 3333 ']→arrayLength = 3->3输入
现在我需要得到一个函数自动触发(marked as ???
)当这种情况发生时,我从我的下拉菜单中选择的东西-例如是我的arrayLength = 3
,它应该被正确的id, indexParent and indexChild
触发3次。怎么解呢?
我需要上面的parameters
在我的方法..
提前感谢!
<div v-for="(id, indexChild) in inputs" :key="indexChild">
<b-dropdown text="Select" right variant="success">
<b-dropdown-item v-for="(item, indexDropdown) in json" :key="indexDropdown" @click="trySomething(item.Number)">{{item.Name}}</b-dropdown-item>
</b-dropdown>
<b-button v-b-toggle="'newElement'+indexParent+indexChild">Element {{indexChild + 1}}></b-button>
<b-collapse :id="'newElement'+indexParent+indexChild"
<div ???="getValues(id, indexParent, indexChild)"> <!-- how can I fire this when created? -->
<!-- Do some more code -->
</div>
</b-collapse>
</div>
<!-- create new "item"-elements -->
<div>
<b-button @click="addElement()">Add element</b-button>
</div>
methods: {
addProduct() {
this.inputs.push({})
},
trySomething(itemValue) {
var array = [];
const products = this.otherJSON.find((i) => i.Number === itemValue);
for (let key in products.ID) {
array.push(products.ID[key]);
}
this.getLengthArray = array.length;
this.inputs.splice(0) //at first I need to delete all to push exact inputs based on arrayLength
for (let i = 0; i < this.getLengthArray; i++) {
this.inputs.push({});
}
},
getValues(id, indexParent, indexChild) { //Here I need the parameters id, indexParent, indexChild
}
},
data() {
return {
inputs: [{}],
}
},
props: ["indexParent"]
我刚才用了:
<div v-if="getValues(id, indexParent, indexChild)" v-once></div>
,我成功了!