Невозможно получить доступ к API Javascript для Office из <script>в диалоге - PullRequest
0 голосов
/ 14 ноября 2018

Далее следует HTML-файл, который передается в displayDialogAsync

<!DOCTYPE html>
<!-- Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license.
4  See LICENSE in the project root for license information -->
<html>

<head>
  <title></title>
  <meta charset="utf-8" />
  <script src="https://appsforoffice.microsoft.com/lib/1/hosted/office.js" type="text/javascript"></script>
  <script type="text/javascript" src="Scripts/jquery-3.3.1.min.js"></script>

  <!-- For the Office UI Fabric, go to http://aka.ms/office-ui-fabric to learn more. -->
  <link rel="stylesheet" href="Content/fabric.min.css">
  <link rel="stylesheet" href="Content/fabric.components.min.css">
  <script>
    Office.initialize = function(reason) {


      write();


    }

    function write() {

      // If I uncomment the line below, the text in the dialog box will NOT be updated            
      //var email = Office.context.mailbox.item.sender.emailAddress;

      $("#firstName").text("John");
      $("#lastName").text("Doe");
      $("#gender").text("Male");
      $("#knownas").text("John Doe");
      $("#citizenship").text("Antarctica");
      $("#language").text("Esperanto");
    }
  </script>
</head>

<body>

  <div class="ms-Gridc ms-font-xxl ms-fontColor-neutralSecondary ms-fontWeight-semilight">
    <div class="ms-Grid-row">
      <div class="ms-Grid-col"><span id="firstName"></span></div>
      <div class="ms-Grid-col"><span id="lastName"></span></div>
      <div class="ms-Grid-col"><span id="gender"></span></div>
    </div>
    <div class="ms-Grid-row">
      <div class="ms-Grid-col"><span id="knownas"></span></div>
      <div class="ms-Grid-col"><span id="citizenship"></span></div>
      <div class="ms-Grid-col"><span id="language"></span></div>
    </div>
  </div>
</body>

</html>

Всякий раз, когда я пытаюсь использовать что-либо из API-интерфейса Office JavaScript, я замечаю, что мое диалоговое окно отображается пустым.

В этом примере все, что я делаю, это присваиваю значение переменной, а остальная часть кода перестает работать.На консоли не отображаются сообщения об ошибках.

1 Ответ

0 голосов
/ 14 ноября 2018

Это ожидаемое поведение.В документации для диалога я обнаружил следующее:

Функция messageParent - это один из двух API-интерфейсов Office, которые можно вызвать в диалоговом окне.Другой - Office.context.requirements.isSetSupported.

...