0

我正在尝试使用对话框 API 的 Excel 插件。

我想创建一个对话框,然后使用 dialog.messageChild 发送消息,但孩子没有收到消息。

这是代码

家长

var loginDialog: Office.Dialog;
async function login(event: Office.AddinCommands.Event) {
  var dialogInput = new DialogInput();
  dialogInput.name = MeekouConsts.DataFromWeb;
  await showDialog(dialogInput);
  //show specific dialog
  // await Office.context.ui.displayDialogAsync(
  //   `${AppConsts.appBaseUrl}/login.html`,
  //   { height: 40, width: 20 },
  //   function (asyncResult) {
  //     loginDialog = asyncResult.value;
  //     loginDialog.addEventHandler(Office.EventType.DialogMessageReceived, processMessage);
  //   }
  // );
  event.completed();
}

async function showDialog(dialogInput: DialogInput) {
  console.log(dialogInput);
  await Office.context.ui.displayDialogAsync(
    `${AppConsts.appBaseUrl}/dialog.html`,
    { height: 40, width: 20 },
    function (asyncResult) {
      dialog = asyncResult.value;
      dialog.addEventHandler(Office.EventType.DialogMessageReceived, dialogMessageFromChild);
      **dialog.messageChild("Hello");**
      log("A3", "ff");
    }
  );
}

孩子

Office.initialize = async () => {
  console.log("ww");
  document.getElementById("send").addEventListener("click", (e:Event) => {
    Office.context.ui.messageParent("Hello World");
  });
  Office.context.ui.addHandlerAsync(Office.EventType.DialogParentMessageReceived, dialogMessageFromParent);
};

function dialogMessageFromParent(arg: any) {
  log("B2","dialog" + JSON.stringify(arg));
  var newlabel = document.createElement("Label");
  newlabel.innerHTML = "Here goes the text";
  document.getElementById("messages").appendChild(newlabel);
  dialogInput = JSON.parse(arg.message) as DialogInput;
  document.getElementById(dialogInput.name).style.display = "inline";
}

dialogMessageFromParent没有被解雇。

4

0 回答 0