最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Nesting template strings in Typescript - Stack Overflow

programmeradmin3浏览0评论

I'm trying to retrieve a variable from an object.

cell: (row: any) => `${row.testcolumn}`

My only issue is that I don't know what 'testcolumn' is ahead of time as I'm doing this dynamically. I'm not sure what to do, and the nested template string strategy I'm attempting will not pile.

cell: (row: any) => `${row.(`${varString}`)}`

I've also tried just using the variable name instead of nesting a template string, but that just looks for the varString value in the object, which doesn't exist. Is there any way I can use a nested literal to substitute the string value into the template literal and it still look for row.testcolumn instead of row.varString?

I'm trying to retrieve a variable from an object.

cell: (row: any) => `${row.testcolumn}`

My only issue is that I don't know what 'testcolumn' is ahead of time as I'm doing this dynamically. I'm not sure what to do, and the nested template string strategy I'm attempting will not pile.

cell: (row: any) => `${row.(`${varString}`)}`

I've also tried just using the variable name instead of nesting a template string, but that just looks for the varString value in the object, which doesn't exist. Is there any way I can use a nested literal to substitute the string value into the template literal and it still look for row.testcolumn instead of row.varString?

Share Improve this question edited Feb 14, 2018 at 22:07 Estus Flask 224k79 gold badges472 silver badges611 bronze badges asked Feb 14, 2018 at 21:58 Vincent MaggioliVincent Maggioli 651 silver badge6 bronze badges 1
  • 1 Would cell: (row: any) => `${row[varString]}` work? Maybe I have misunderstood. – CRice Commented Feb 14, 2018 at 22:02
Add a ment  | 

1 Answer 1

Reset to default 7

It is same for template literals as for regular JS. Object properties can be retrieved dynamically with bracket notation, row[varString].

It will be:

cell: (row: any) => `${row[varString]}`
发布评论

评论列表(0)

  1. 暂无评论