Home > Net >  vue filtering method how it works
vue filtering method how it works

Time:12-30

Here's the some code i try what I did

  deleteajobewith_events(event){

     const data =event.store.readQuery({
        query: ClientJobesList,
        variables: {id:1} 
      });
    data.client.jobes.filter(jobee=>jobee.id != 101);

    console.log(data);
    event.store.writeQuery({ query: ClientJobesList, data});
 }

If I console log the 'data', it shows the same data without filtering

this is a hint about the 'data' object

 {
 "data": {
"client": {
  "id": "1",
  "client_name": "Marouane",
  "jobes": [
    {
      "id": "101",
      "title": "cbkvjk",
      "order": 88,
      "client_id": "1"
    },
  .........
    ]
  }
}
}

CodePudding user response:

Filter creates new array, and data must be the same type (101 is not the same as "101") so try like following:

 const data= {
  "client": {
    "id": "1",
    "client_name": "Marouane",
    "jobes": [
      {
        "id": "101",
        "title": "cbkvjk",
        "order": 88,
        "client_id": "1"
      },
      {
        "id": "102",
        "title": "aaa",
        "order": 99,
        "client_id": "2"
      },
    ]
  }
}
data.client.jobes = data.client.jobes.filter(jobee=>jobee.id !== '101');
console.log(data)

CodePudding user response:

u haven't assign filtered data to previous one :

  deleteajobewith_events(event){

  const data =event.store.readQuery({
    query: ClientJobesList,
    variables: {id:1} 
   });
  data.client.jobes = data.client.jobes.filter(jobee=>jobee.id != 101);

   console.log(data);
   event.store.writeQuery({ query: ClientJobesList, 
data});
}
  • Related