簡體   English   中英

如何為對象值分配兩個不同的變量?

[英]How to assign two different variables to an object value?

不知道我的標題是否有意義,但這是我在做題時遇到的問題。

我有兩個HTML輸出:

let output1 = `<h1>Header</h1>`
let output2 = `<div> // content </div>`

我有這個:

let mailOptions2 = {
      from: '"xyz" <xyz@info.com>', // sender address
      to: mailList, // receiver or receivers
      subject: 'XYZ', // Subject line
      html:       // html body
  };

我想將output1output2分配給html 我試圖將兩者都放入一個數組中,但它始終給出未定義的錯誤。 所以我想將output1發送到mailList中的第一個地址,依此類推。 解?

嘗試吸引他們:

html: output1 + output2

編輯:隨着更新的要求;

將變量放入數組中。

let output = [`<h1>Header</h1>`, `<div> content </div>`, ....]

然后在循環內創建mailOptions變量。

for(i = 0; i < mailList.lngth; i++) {
    let mailOptions = {
        from: '"xyz" <xyz@info.com>',
        to: mailList[i],
        subjects: 'XYZ',
        html: output[i] 
    }
}

這應該工作:

outputs = ["1st HTML", "2nd HTML"];

for(var i = 0; i < mailList.length; i++){
    let mailOptions2 = {
        from: '"xyz" <xyz@info.com>',
        to: mailList[i],
        subject: 'XYZ',
        html: outputs[i % outputs.length]
    };
    // send your email here
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM