I am new to Vue.js - it would be so great to receive help . thanks.
I have the API working fine and the Select works fine - SO the code below is working -- EXCEPT it has duplicate values showing.Null values have been removed -- but duplicates are still there.
I would like to solve how to filter the list for the select dropdown to have unique values.
Here is the Model (cut down)
class USERaffylinks(models.Model):
owner_link_useraffyid = models.ForeignKey(USERaffiliates, on_delete=models.CASCADE) #link(s) for each partner stores the id from USERaffiliates
owner_link_short = models.CharField(max_length=27, null=True, default=None, blank=True)
owner_link_long = models.URLField(max_length=100, null=True, default=None, blank=True)
linked_from_typedesc = models.CharField(max_length=12, null=True, default=None, blank=True)
Here is the API code with COMPUTED CODE
export default {
name: 'addlink',
data() {
return {
links: [],
linkitem: 0,
}
},
props: ['value'],
created: function(){
this.getLinks()
},
computed: {
options() {
const unique_ids = [ ...new Set( // make list of unique ids
this.links
.filter(link => Boolean(link.linked_from_typedesc)) // removes falsey like null
.map(link => link.linked_from_typedesc)) // returns linked_from_typedesc only
];
return this.links.filter(link => unique_ids.includes(link.linked_from_typedesc));
},
},
methods: {
getLinks() {
axios.get("http://127.0.0.1:8000/api/affypartnerlinks/")
.then(function (response) {
this.links = response.data;
}.bind(this));
},
And here is the HTML
<div v-if="!addtype">
<select id="linktypelist" v-model="linkitem">
<option disabled value="0">Select or Add</option>
<option v-for='link in options' v-bind:value="link.linked_from_typedesc" :key="link.id" >{{ link.linked_from_typedesc }}</option>
</select>
</div>
IMAGE OF DROP DOWN with duplicates
IMAGE OF DROP DOWN with duplicate
So this all works fine except the duplicate showing up - which I want to remove
I am using the final value selected in link.linked_from_typedesc to store in my table.
Thanks kindly David