chrisgrim
171
3
Vue

Picking the correct Object from a collection

Posted 4 months ago by chrisgrim

Hi,

I am having trouble picking a specific variable from a collection. I am passing into my vue component organizers and a single event. In that event I have a organizer_id column that relates to the id of the categories. I was using this method

props: {
        items: {
            type: Array,
        },
        event: {
            type: Object,
        }
    },

data() {
        return {
            name: '',
        };
    },

methods: {
init() {
this.name = this.items[this.event.organizer_id - 1].organizationName;
}
}

what I realized is that using this.items[] only works if I never delete or skip id numbers in my database!! Very quickly my event organizer id didn't line up with the correct organizer id. So how would I ensure that the event->organizer_id is the used to get the correct item from the list?

I hope this makes sense! Thanks

Please sign in or create an account to participate in this conversation.