Outlook加载项中的RoamingSettings似乎无法正常工作

时间:2018-12-10 13:05:51

标签: outlook-addin office-addins outlook-web-addins

我当前在Outlook中使用img.onload存储两个值。这是我用来存储值的代码段,

validators: {
    imageRes: {
        expression: function($viewValue, $modelValue) {
            var value = $modelValue || $viewValue;

            return $q(function(resolve, reject) {
                if(value) {
                    console.log('IF VALUE');
                    var src = "data:" + $viewValue.filetype + ";base64," + $viewValue.base64;
                    var img = new Image();
                    img.src = src;

                    img.onload = function() {
                        $viewValue.dimensions = {
                            width: img.width,
                            height: img.height
                        };

                        resolve($viewValue.dimensions.height <= 500 && $viewValue.dimensions.width <= 500);
                    };
                } else {
                    resolve(true);
                }
            }).then(
                function(response) {
                    console.log('response = ', response)
                    return response;
                }
            );
        },
        message: '"Too big"'
     }
 }

我第一次运行时,两个值都保存了。然后,我使用此代码段删除了两个值,

RoamingSettings

然后尝试再次将这两个值相加,我看到只有“名称”被存储。我发现有时它可以工作(两个值都是存储的),并且大多数时候只保存“名称”值。

我还注意到的另一件事是,我用密钥'userEmail'保存了另一个密钥对,以检查roamingSettings,即使我先使用Office.context.roamingSettings.set("email", email); Office.context.roamingSettings.saveAsync(function(res){console.log(res);}); Office.context.roamingSettings.set("name", name); Office.context.roamingSettings.saveAsync(function(res){console.log(res);}); 然后再使用{{ 1}}

1 个答案:

答案 0 :(得分:1)

这是由于saveAsync的异步特性。等待保存或在所有编辑后保存。通过不等待saveAsync完成,您将覆盖漫游设置。

Office.context.roamingSettings.set("email", email);

Office.context.roamingSettings.saveAsync(function(res){
    //Wait for save - callback method.
    console.log(res);
    Office.context.roamingSettings.set("name", name); 
    Office.context.roamingSettings.saveAsync(function(res) {
      console.log(res);
    });
})

Office.context.roamingSettings.set("email", email);
Office.context.roamingSettings.set("name", name);
Office.context.roamingSettings.saveAsync(function(res){console.log(res);})