Answer the question
In order to leave comments, you need to log in
vue-tables-2. How to display data from nested objects?
Hello.
To display lists on the project I use Vue-tables-2.
How to display data in a column if it is in a nested object.
For example:
{
id: 1,
category: {
name: 'Категория 1',
}
user: {
name: 'Иван Иванов',
city: {
name: 'Москва'
},
country: {
name: 'Россия'
}
}
}
columns: [
'id',
'contactName',
'contactCity',
'category',
],
options: {
templates: {
contactName(h, row){
return row.user ? row.user.name : '';
},
contactCity(h, row){
return row.user.city ? row.user.city.name : '';
},
category(h, row){
return row.category ? row.category.name : '';
}
},
}
Answer the question
In order to leave comments, you need to log in
Search by properties of nested objects "out of the box" is not provided. So crutches are indispensable.
I see three options:
{ user: { city: { name: "..." } } }
, but will be { userCityName: "..." }
or { user_city_name: "..." }
, something like that.And what's the problem to bring your object to the form that is suitable for the table.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question