I need to map interface properties to objects:
interface Activity {
id: string,
title: string,
body: string,
json: Object
}
I currently do:
headers: Array<Object> = [
{ text: 'id', value: 'id' },
{ text: 'title', value: 'title' },
{ text: 'body', value: 'body' },
{ text: 'json', value: 'json' }
]
This gets very repetitive. What I would like is something like this:
headers: Array<Object> = Activity.keys.map(key => {
return { text: key, value: key }
})
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…