How do I reference a field name that contains a dot in underscore template?

110 Views Asked by At

I have the data object like this:

var data = {};
data['T.Name'] = 'World';

I would like to execute this template:

_.template('Hello <%= T.Name %>!', data)

Error:

ReferenceError: T is not defined

I understand that underscore tries to take T object with the Name property. But I need to make it work with 'T.Name', because I have no chance to change the data format. Please help me!

1

There are 1 best solutions below

1
On

You can try this:

_.template('Hello <%= data["T.Name"] %>!', data)