如何在 google 应用程序脚本对话框的提示中添加换行符?

How can I add line breaks to the prompt in a google apps script dialogue box?

我正在尝试使用 g-app 脚本在对话框中提供多行提示消息。

生成的对话框将是:


第 1 行的内容。

第 2 行的内容

第 3 行的内容

您确定要继续吗?

是/否


代码如下:

function testing() {

var ui = DocumentApp.getUi();

const line1 = 'Content of line 1.';
const line2 = 'Content of line 2.';
const line3 = 'Content of line 3';

var dialogueMessage = [line1]+'\n'+
                [line2]+'\n'+
                [line3]

Logger.log(dialogueMessage); //Test message content. Looks correct, with three lines.

var result = ui.alert(
      dialogueMessage,
      'Are you sure you want to continue?',
      ui.ButtonSet.YES_NO);

}

当我记录消息时出现了三个单独的行,但对话框本身没有反映任何换行符。任何人都知道如何将这些中断添加到对话消息中?

感谢

尝试:

function myFunction() {

  const ui = DocumentApp.getUi();

  const line1 = 'Content of line 1.';
  const line2 = 'Content of line 2.';
  const line3 = 'Content of line 3';

  const dialogueMessage = `${line1}\n${line2}\n${line3}`

  const result = ui.alert(
        `${dialogueMessage}\n\nAre you sure you want to continue?`,
        ui.ButtonSet.YES_NO);

}

你的错误是你没有正确地包括你的 dialogueMessage

var result = ui.alert(
  dialogueMessage,
  'Are you sure you want to continue?',
  ui.ButtonSet.YES_NO);

更正:

var result = ui.alert(
  '' + dialogueMessage + '\nAre you sure you want to continue?',
  ui.ButtonSet.YES_NO);

另请参阅: