从 javascript 后端推送数据时如何在新行中打印 html 文本

问题描述 投票:0回答:1

formatPopupBodyText(serverPayload){ 让结果 = this.formatBusinessHoursText(serverPayload);

    if (serverPayload.PhoneNumbers__c != null && getCurrentCountryCode() === 'IN' && (this.brandName == 'HYN' || this.brandName == 'SUZ')) {
       
        result += `. ${LABEL_NATIONALNETWORK} `;
    }
   
    this.popupBodyText = result;
}

现在显示如下:作为一条语句::

我们的营业时间为周一至周五上午 9 点至下午 6 点。联系我们80004001。(打全国网)

我试过下面的代码但没有用:

formatPopupBodyText(serverPayload){ 让结果 = this.formatBusinessHoursText(serverPayload);

    if (serverPayload.PhoneNumbers__c != null && getCurrentCountryCode() === 'IN' && (this.brandName == 'HYN' || this.brandName == 'SUZ')) {
       
        result += `\n ${LABEL_NATIONALNETWORK} `; **//put "\n" and tried with "<br/>" as well**
    }
   
    this.popupBodyText = result;
}

输出应该像下面这样意味着每个句子都应该换行。但现在它显示在一个声明中::

我们的营业时间为周一至周五上午 9 点至下午 6 点。
联系我们80004001。
(拨打全国网络)

javascript html newline line-breaks lwc
1个回答
0
投票

可以使用换行符 或 HTML 标签 < br > 和一些修改

formatPopupBodyText(serverPayload) {
  let result = this.formatBusinessHoursText(serverPayload);

  if (serverPayload.PhoneNumbers__c != null && getCurrentCountryCode() === 'IN' 
  && (this.brandName == 'HYN' || this.brandName == 'SUZ')) {
  result += `<br>${LABEL_NATIONALNETWORK}`; // add <br> tag before the label
 }

 this.popupBodyText = result;
}
© www.soinside.com 2019 - 2024. All rights reserved.