I have an input where users can search for titles.
Date picker which is used mengxiong10/vue2-datepicker. (Any other picker is welcome)
How can the array be filtered by only Search, only Date, or both Search and Date? (Search via Title works ).
How would the search be in array vs nested array?
HTML-
<input class="form-control" type="text" v-model="search" placeholder="Search" /></div>
<date-picker v-model="datefilter" range></date-picker>
<div v-for="item in resultQuery">
{{item.title}}
</div>
Vuejs-
<script>
import DatePicker from 'vue2-datepicker';
import 'vue2-datepicker/index.css';
export default {
el: '#app',
components: { DatePicker },
data() {
return {
search: null,
resources:[
{title:"AAA",date: 1622192760},
{title:"BBB",date: 1622624760},
{title:"CCC",date: 1620810360},
{title:"DDD",date: 1625907960},
{title:"EEE",date: 1623315960},
],
resources2:[
{id:1,items: [{ title: 'a',date: 1622192760 }, {name: 'aa', date: 1622624760 }]},
{id:2,items: [{ title: 'b',date: 1623315960 }, {name: 'bb', date: 1625907960 }]},
{id:3,items: [{ title: 'c',date: 1622624760 }, {name: 'cc', date: 1622624760 }]},
{id:4,items: [{ title: 'd',date: 1622624760 }, {name: 'dd', date: 1622624760 }]},
{id:5,items: [{ title: 'e',date: 1622192760 }, {name: 'ee', date: 1622624760 }]},
],
datefilter: null,
};
},
computed: {
resultQuery(){
if(this.search){
return this.resources.filter((item)=>{
return item.title.toLowerCase().includes(this.search.toLowerCase())) }
})
}else{
return this.resources;
}
}
}
};
</script>