I would like to create a simple web apps that can display all json data and user can filter it?
here it my code I am using Vue 2
index.html
<div id="app">
<input type="input" id="txt-search" v-model="mySearch">
<select>
<option :value="post.id" v-for="post in searchBook"
>{{post.id}}</option>
</select>
</div>
script.js
var json_data = 'jsonfile.json'
var app = new Vue({
el: '#app',
data: {
posts: null,
mySearch:''
},
created: function () {
this.fetchData()
},
methods: {
fetchData: function () {
var xhr = new XMLHttpRequest()
var self = this
xhr.open('GET', json_data)
xhr.onload = function () {
self.posts = JSON.parse(xhr.responseText)
}
xhr.send()
}
},
computed: {
searchBook() {
return this.mySearch ? this.posts.filter(post => {
return post.title.includes(this.mySearch);
})
: this.posts;
}
}
})
It only filter title data
post.title.includes(this.mySearch)
Is it posible to filter all json data like
post.*.includes(this.mySearch)