How to update this function to my database response ?
getItems(ev: any) {
// Reset items back to all of the items
this.initializeItems();
// set val to the value of the searchbar
let val = ev.target.value;
// if the value is an empty string don't filter the items
if (val && val.trim() != '') {
this.items = this.items.filter((item) => {
return (item.toLowerCase().indexOf(val.toLowerCase()) > -1);
})
}
item will be one of the objects from the array. If you want to filter based on each object’s description, you just need to use item.description, so something more like this:
joshmorony, good day! Could you suggest please, how to implement, that every time this.initializeItems(); do not show all items ? Filter return zero if i do not have such items, but i always see all items …
This is my reset. Request to database.
this.initializeItems() {
this.Service.get(this.id).then(data=>{
for(let i = 0; i < data.res.rows.length; i++) {
this.models.push(data.res.rows.item(i));
}
})
}
getItems(ev: any) {
// Reset items back to all of the items
this.initializeItems();
// set val to the value of the searchbar
let val = ev.target.value;
// if the value is an empty string don't filter the items
if (val && val.trim() != '') {
If anyone has this same problem, the issue is quite simple to solve.
When you’re using a database response, those are async petitions to the systems.
If you do that in a sequence order, you will get problems.
So as an example, I have a class databaseServiceProvider with a function getAllProducto returning a Promise.
A promise has a then and a catch function to check the answer of my petition.
The filters must be donde inside the
.then(data => {// filter code here}) .catch( e => {// catch the error })
Because there is where the data is available and the info is full.
Hope it helps anybody.