【问题标题】:Outlook add-in - blank body after replacing scrolling textOutlook 加载项 - 替换滚动文本后的空白正文
【发布时间】:2017-01-04 20:21:09
【问题描述】:

我正在开发适用于 Outlook 2016 的 Office365 插件,它允许用户使用任务窗格中的按钮更改电子邮件的正文。

任务窗格中的 HTML:

 <p><button onclick="createLongBody()">Set Long Body</button></p>
 <p><button onclick="createShortBody()">Set Short Body</button></p>
 <div id="status"></div>

在 Javascript 中:

function createLongBody() {

    var longText = "<html><body>Hello<br/>Hello<br/>Hello<br/>Hello<br/>Hello<br/>Hello<br/>Hello<br/>Hello<br/>Hello<br/>Hello<br/>Hello<br/>Hello<br/>Hello<br/>Hello<br/>Hello<br/>Hello<br/>Hello<br/>Hello<br/>Hello<br/>Hello<br/>Hello<br/>Hello<br/>Hello<br/>Hello<br/>Hello<br/>Hello<br/>Hello<br/>Hello<br/>Hello<br/>Hello<br/>Hello<br/>Hello<br/>Hello<br/>Hello<br/>Hello<br/>Hello<br/>Hello<br/>Hello<br/>Hello<br/>Hello<br/>Hello<br/>Hello<br/>Hello<br/>Hello<br/>Hello<br/>Hello<br/>Hello<br/>Hello<br/>Hello<br/>Hello<br/>Hello<br/>Hello<br/>Hello<br/>Hello<br/>Hello<br/>Hello<br/>Hello<br/>Hello<br/>Hello<br/>Hello<br/>Hello<br/>Hello<br/>Hello<br/>Hello<br/>Hello<br/>Hello<br/>Hello<br/>Hello<br/>Hello<br/>Hello<br/>Hello<br/>Hello<br/>Hello<br/>Hello<br/>Hello<br/>Hello<br/>Hello<br/>Hello<br/>Hello<br/>Hello<br/>Hello<br/>Hello<br/>Hello<br/>Hello<br/>Hello<br/>Hello<br/>Hello<br/>Hello<br/>Hello<br/></body></html>";
    Office.context.mailbox.item.body.setAsync(longText, { coercionType: Office.CoercionType.Html }, function () {
        $("#status").html("Long email complete!");
    });
};

function createShortBody() {
    Office.context.mailbox.item.body.setAsync("<html><body><h1>Hello</h1></body></html>", { coercionType: Office.CoercionType.Html }, function () {
        $("#status").html("Short email complete!");
    });

复制:

  1. 点击“创建长体”按钮
  2. 滚动到底部,将光标放在电子邮件末尾
  3. 点击“创建短正文”按钮

结果:

状态文本更改为“短电子邮件完成”,但没有出现新的短电子邮件 - 正文只是空白。

我不确定这是否是 Office 插件 API 错误,但我想将它呈现给社区,看看是否有人有任何想法? 其他人可以复制吗?谢谢!

用 HTML/JS 编辑以复制

【问题讨论】:

    标签: ms-office office365 outlook-addin


    【解决方案1】:

    我试过你的代码,它对我有用。我复制粘贴了您的函数并运行 createLongBody() 然后 createShortBody() 并替换了电子邮件的正文。

    您使用的是哪个版本的 Outlook?

    【讨论】:

    • 在 Outlook 2016 中。单击短电子邮件按钮时,光标是否位于长电子邮件的底部?仅当您滚动到底部并单击时才会发生这种情况,因此您的光标位于长电子邮件的末尾。 (见步骤#2)。感谢您尝试复制!
    • 是的,我点击了,所以插入指针位于最后一个 Hello 的末尾(在运行 createLongBody() 函数之后)。有没有具体的Outlook 2016版本号,可以通过文件->Office账号->关于Outlook获取
    • 版本 16.0.4266.1003(32 位)
    【解决方案2】:

    你是不是在第一次改变body context的回调中调用了后续调用?如果不是,它可能无法正常工作,因为 setAsync 是异步函数。

    我正在尝试重现此问题,但失败了。下面的测试功能对我很有效:

      function setBody() {
        var theHtml = "<html><body><h1>Hello</h1><h2> Jack,</h2><h3>Rose</h3> <h4>..</h4><h1>Hello</h1><h2> Jack,</h2><h3>Rose</h3> <h4>..</h4><h1>Hello</h1><h2> Jack,</h2><h3>Rose</h3> <h4>..</h4><h1>Hello</h1><h2> Jack,</h2><h3>Rose</h3> <h4>..</h4><h1>Hello</h1><h2> Jack,</h2><h3>Rose</h3> <h4>..</h4></body></html>";
        Office.context.mailbox.item.body.setAsync(theHtml, { coercionType: Office.CoercionType.Html }, function (asyncResult) {
           var newHtml= theHtml.replace(/Rose/g, "rose");
           Office.context.mailbox.item.body.setAsync(newHtml, { coercionType: Office.CoercionType.Html });
        });
    }
    

    如果您仍有问题,您介意分享一个完整的代码来帮助我们重现此问题吗?

    【讨论】:

    • 感谢@FeiXue!我用更多代码编辑了这个问题,以更好地反映情况。我没有以编程方式运行第二次编辑;用户必须单击另一个按钮才能再次更改正文。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-24
    • 2015-08-08
    相关资源
    最近更新 更多