2013-01-08 20 views
0

我试图在有人试图关闭未保存的文件时在我的Windows RT应用程序中启动保存对话框。但是,我不断收到一个0x80070005 - JavaScript runtime error: Access is denied错误使用Javascript的Windows Store应用程序中的访问被拒绝

这是我使用启动消息对话框的代码。当选择“不保存”(并且运行BlankFile())时,一切都运行正常。然而,当你选择“保存文件”它抛出的访问被拒绝错误时尝试运行.pickSaveFileAsync()

function createNewFile() 
{ 
    if (editedSinceSave) 
    { 
     // Create the message dialog and set its content 
     var msg = new Windows.UI.Popups.MessageDialog("Save this file?", 
      "Save Changes"); 

     // Add commands 
     msg.commands.append(new Windows.UI.Popups.UICommand("Don't Save", 
      function (command) { 
       BlankFile(); 
      })); 

     msg.commands.append(new Windows.UI.Popups.UICommand("Save File", 
      function (command) { 
       //saveFile(true, true); 
       testPop("test"); 
      })); 

     // Set the command that will be invoked by default 
     msg.defaultCommandIndex = 2; 

     // Show the message dialog 
     msg.showAsync(); 
    } 
} 

function testPop(text) { 
    var msg = new Windows.UI.Popups.MessageDialog(text, ""); 
    msg.showAsync(); 
} 

回答

1

你的核心问题是你正在绑定显示另一个消息对话框ontop。我讨论的细节和解决方案在这里: What is the alternative to `alert` in metro apps?

然而,你自然需要这是发生 - 我建议看着建立一个不同类型的流而不是堆叠对话框。

+0

啊!我明白你对这个流程的看法,但这里有什么选择?如果有人试图关闭文件而不保存,则标准过程是提示他们保存并显示文件选择器对话框。我没有看到围绕此流程的解决方法 – roryok

+0

您可以通过将WinJS.promise.timeout延迟推送到选取器来解决此问题。 –

+0

看起来好像showAsync的功能更好。我想我会像 – roryok

0

的办法解决,这似乎是设置命令ID,赶上它的showAsync()done()功能,如所以

function createNewFile() 
{ 
    if (editedSinceSave) 
    { 
     // Add commands and set their CommandIds 
     msg.commands.append(new Windows.UI.Popups.UICommand("Dont Save", null, 1)); 
     msg.commands.append(new Windows.UI.Popups.UICommand("Save File", null, 2)); 

     // Set the command that will be invoked by default 
     msg.defaultCommandIndex = 1; 

     // Show the message dialog 
     msg.showAsync().done(function (command) { 
      if (command) { 
       if (command.id == 1){ 
        BlankFile(); 
       } 
       else { 
        saveFile(true, true); 
       } 
      } 
     }); 
    } 
} 

这不会引发任何错误。我不知道为什么用另一种方式抛出错误,因为它看起来没有什么不同!

+0

当然,它是不同的。在您的原始代码中,您尝试通过向保存命令添加一个函数来在现有代码上创建一个对话框,这在WinJS应用程序中是不允许的。 在您修改后的版本中。你在钩住“完成”延续方法。所以现在,在关闭弹出窗口后(通过点击“保存文件”按钮),你的“保存文件”代码将被执行。 顺便说一下,从逻辑上讲,这也是正确的做法。一旦用户点击了保存按钮,就不再需要该对话框了。 – guyarad

相关问题