[SOLVE] Object as arg in component page

Hi,

using Template7 with an array of object. Could I set as arg for a method the object using {{this}} ?

example :
{{#each persons}}
<a href=’#’ @click=‘gender({{this}})’>
{{/each}}

regards,

Guillaume

Nope, template7 will try to render it as a string. As a workaround you will need to pass here @index:

{{#each persons}}
<a href=’#’ @click=‘gender({{@index}})’>
{{/each}}

And in method handle index, for example:

gender(index) {
  var person = this.persons[index];
  ...
}

OK tanks so I have another problem because that what I made in a component page but I get:

undefined is not an object (evaluating ‘_this.persons’)

this is my component script :
data: () => {
return {
persons : [
{
name: ‘TEST1’,
gender: ‘male’
},
{
name: ‘TEST2’,
gender: ‘female’
}
]
}
},
methods: {
gender: (index) => {
let person = this.persons[index];
console.log(person);
}
}
}

I found that this is undefined ?!?

I am using framework7-cli

Don’t use arrow function for methods :wink: