3
我需要的接口屬性映射到對象:打字稿迭代接口屬性
interface Activity {
id: string,
title: string,
body: string,
json: Object
}
我目前做的:
headers: Array<Object> = [
{ text: 'id', value: 'id' },
{ text: 'title', value: 'title' },
{ text: 'body', value: 'body' },
{ text: 'json', value: 'json' }
]
這會非常反覆。我想要的是這樣的:
headers: Array<Object> = Activity.keys.map(key => {
return { text: key, value: key }
})