in api response if value present in json remove item from dropdown
Wanted to remove some value from dropdown when user added successfully. i am calling one api for checking that parents in josn or not if parents array not empty i want to remove that value from dropdown and show rest
my code
<v-chip v-for="items in checkParents" :key="items.value" :value="items.value">{{ items.name }}</v-chip>
in computed
checkParents: function (){
if (!_.isEmpty(this.familyTreeData.individualInfo.parents))
{
console.log(this.familyTreeData.individualInfo.parents)
if (!_.isNull(this.familyTreeData.individualInfo.parents[0].gender === 'male')){
return _.remove(this.items, function (n){
let c = n.name !== 'Father'
return c;
})
}
}else {
return this.items
}
}
For example i have added father then wanted to remove father array that is on parents[0] position and my mother in parents[1] position or if i add Mother & father both want to remove both from dropdown
I think the easiest way to do it is by having two data properties and a computed.
One of your data property would contain all your items.
The second one would contain all items that were added. So when you get your API response, you can populate this array.
Then in the computed you can filter out added items.
You can also "hard remove" items directly in your API response, but that means your items would be altered permanently. If that doesn't matter to much (for example, if you don't have a situation where added items can be removed), you could have only a single data property without any computed. You could actually still manage to bring back items in your array, but you wouldn't have a way to make sure it was there originally.