calling function stored as a property in an object in a for loop

Selage

In my template i'm rendering a v-list using a v-for.

<v-list dense>
  <template v-for="(menuItem, index) in menuItems">
    <v-list-item :key="index" @click.stop="menuItem.function">
      <v-list-item-icon>
        <v-icon :color="menuItem.color">{{ menuItem.icon }}</v-icon>
      </v-list-item-icon>
      <v-list-item-title> {{ menuItem.title }} </v-list-item-title>
    </v-list-item>
  </template>
</v-list>

in my script section i'm doing this

data: () => ({
    menuItems: [
        {
            title: 'Lijst samenklappen',
            icon: 'mdi-arrow-top-left-thin-outline',
            color: 'grey',
            function: 'collapse'
        },
        {
            title: 'Onderdeel toevoegen',
            icon: 'mdi-plus-circle',
            color: 'green',
            function: 'add'
        },
        {
            title: 'Bestaand onderdeel toevoegen',
            icon: 'mdi-plus-circle',
            color: 'green',
            function: 'addExisting'
        },
        {
            title: 'Dit onderdeel verwijderen',
            icon: 'mdi-minus-circle',
            color: 'red',
            function: 'disable'
        }
    ]
}),
methods: {
    cardClick() {
        this.$nuxt.$emit('set-part', this.tab)
    },
    add() {
        this.$nuxt.$emit('add-part', this.part.PK_R_ASSEMBLY)
    },
    addExisting() {
        this.$nuxt.$emit('add-existing-part', this.part.PK_R_ASSEMBLY)
    },
    disable() {
        this.$nuxt.$emit('disable-part', this.part.PK_R_ASSEMBLY)
    },
    collapse() {
        this.$nuxt.$emit('collapse', this.tab.PK_R_ASSEMBLYDETAILSUBASSEMBLY)
    },
    open() {
        this.$nuxt.$emit('open', this.tab.PK_R_ASSEMBLYDETAILSUBASSEMBLY)
    }
}

I've tried several way's to try and call the function by the property value in the object. No luck

Does anybody have an idea how to do this? Not all code is displayed, as I don't think it is relevant to the question.

norbekoff

You can change your click event like this:

 @click.stop="handleEvents(menuItem.function)"

And add a new function to your methods object to call functions:

methods: {
   handleEvents(funcName) {
     this[funcName]()
   } 
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Derived property calling stored function throws StreamCorruptedException

From Dev

Calling function, from callback stored in object, in an array

From Dev

Call a Javascript function stored in an object property

From Dev

Javascript - calling an external function as a property of an object

From Dev

Calling a function within an object property from another property

From Dev

Why is a stored function in an object property being overwritten (Python)?

From Dev

"Trying to get property of non-object" error in calling a library function

From Dev

Randomly calling an object property

From Dev

Calling a function that's stored in a map

From Dev

MySql - Creating Stored Function and Calling It

From Dev

Calling a stored function that returns nothing

From Dev

Calling the property of an object returns object instead of property

From Dev

Calling a function through a for loop

From Dev

javascript function calling in loop

From Dev

Calling function directly in for loop

From Dev

Calling function in loop header

From Dev

Calling a function to a loop

From Dev

Calling a Function Inside a Loop

From Dev

Run a Function Stored in an Object

From Dev

Accessing property of object stored in Dataframe

From Dev

Calling a function in a loop of another function

From Dev

NSubstitute - setting a property of the calling object

From Dev

JS Calling Object Property by Variable

From Dev

Calling a function with a variable object

From Dev

Get Object of Calling Function

From Dev

Calling a function as object variable?

From Dev

Object property reassignment in a loop

From Dev

Object property lost in loop

From Dev

Calling a function and property the same way?

Related Related

HotTag

Archive