我正在嘗試使用lodash _.template
創建一個帶有Node.js的HTML電子郵件模板。當我使用下面的代碼時,出現此錯誤:((__t = (firstName)) == null ? '' : __t) +
。對電子郵件使用lodash ._模板
有關我在做什麼錯的任何想法?另外,應該只有一個爲所有動態字段編譯的模板?
var firstName = _(contactinfo).pluck('firstName');
var compiledFirst = _.template('template with <%= firstName %>!');
var htmlFirst = compiledFirst(firstName);
var lastName = _(contactinfo).pluck('lastName');
var compiledLast = _.template('template with <%= lastName %>!');
var htmlLast = compiledLast(lastName);
var data = {
from: [email protected],
to: email,
subject: 'Your Order Confirmation',
html: '<p>Dear '+ htmlFirst + htmlLast+': '</p><br>
<p>Thank you for your order. . . </p><table><tr>
<thead><th><strong>Items</strong></th></thead></tr></table>'
}
這裏是陣列的樣子:
[
{
"address": "555 Broadway",
"city": "New York",
"email": "[email protected]",
"firstName": "John",
"lastName": "Doe",
"phone": "2125551212",
"state": {
"code": "NY",
"state": "New York"
},
"value1": true,
"zip": "10001",
"$id": "-K-qmfZzHgQaEM7uHKEK",
}
]
你正在爲'lastName'做'pluck('firstName')' –
@Explosion Pills感謝你的指出。修正它上面。 – Ken