I'm working on a search bar for a project. I have the search bar refer to my data list but I can't get the content to show on screen. I know the array the data list uses is correct because it displays with a regular un-ordered list. I can make a static array show within my datalist but not my dynamic search array.
<div>
<!-- Search Bar -->
<b-form-input
v-model="text"
type="text"
placeholder="Search Courses/Professors"
list="search-list-id"
@input="searchInputChanged"
></b-form-input>
<!-- Displayes Filtered List -->
<li id="my-list-1" v-for="(item, index) in searchArray" :key="index">{{item}}</li>
<!-- Datalist for Search Bar -->
<datalist id="search-list-id">
<!-- This one shows -->
<option v-for="(size,index) in sizes" :key="index">{{ size }}</option>
<!-- This one doesn't show. WHY? -->
<option v-for="(item, index) in searchArray" :key="index">{{item}}</option>
</datalist>
</div>
</template>
<script>
import axios from "axios"; // Communicates w/ backend
export default {
/* eslint-disable no-console */
name: "Search",
components: {},
data() {
return {
text: "",
searchArray: [],
sizes: ["Small", "Medium", "Large", "Extra Large"]
};
},
methods: {
searchInputChanged() {...},
getSearchFromBackend() {...}
},
computed: {
filteredProfessors() {...}
}
};
</script>
So I can display a static array with data list just fine... My sizes array is visible from the dropdown
But my dynamic list, which I know has the correct array because it display fine in my doesn't show Dynamic array not showing w/in dropdown
I can't seem to figure this one out. Any ideas?
Here is the content of my methods...
methods: {
searchInputChanged() {
if (this.text.length > 1) this.getSearchFromBackend();
},
getSearchFromBackend() {
// get the search from the backend
new Promise((resolve, reject) => {
this.status = "loading"; // we can show a loading wheel while in this state
var dataToPassIn = { filter: this.text };
axios({
url: "/search/" + this.text,
data: dataToPassIn,
method: "GET"
})
.then(resp => {
console.log(resp);
this.searchArray = resp.data;
this.status = "success";
resolve(resp);
})
.catch(err => {
console.log(err);
this.status = "error";
reject(err);
});
});
}
},