I'm trying to dynamically add drowdown list items using bootstrap-vue, and I'm having trouble getting the dropdown list items to render to the browser. Here's what I have so far, any input would be much appreciated. I want it to be dynamics so that if the original JSON ever changes the dropwdown list items will change with it without having to go back and change the code.
NOTE: the reportData is a list of objects, which is why I'm setting the first element of the reportData to the newData that i want the dropdown list items to be rendered from.
Dropdown List Component:
<section class="drop-down">
<div>
<b-dropdown id="dropdown-list" text="Error Reports" class="m-md-2">
<b-dropdown-item >ITEM</b-dropdown-item>
<b-dropdown-divider></b-dropdown-divider>
</b-dropdown>
</div>
<button @click="changeReport">Click to change</button>
</section>
</template>
<script lang="js">
export default {
name: 'drop-down',
props:['reportData'],
data () {
return {
newData: this.reportData[0]
}
},
methods: {
changeReport(){
this.newData = this.reporData[1]
}
},
watch: {
newData : function(val, OldVal){
var dropdownList = document.getElementById("dropdown-list")
for (var key in val){
console.log(key)
var dropdownItem = document.createElement('b-dropdown-item')
dropdownItem.value = key
dropdownList.add(drowdownItem, 0)
}
}
}
}
</script>
<style>
</style>