Javascript commonModalDialogClose(SP.UI.DialogResult.OK, someValue) 抛出错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8901387/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 08:00:09  来源:igfitidea点击:

commonModalDialogClose(SP.UI.DialogResult.OK, someValue) throws error

javascriptsharepoint

提问by Paul

In SharePoint 2010 I have a visual web part that uses SP.UI.ModalDialog.showModalDialog

在 SharePoint 2010 中,我有一个可视化的 Web 部件,它使用 SP.UI.ModalDialog.showModalDialog

The dialog shows up fine but when I try to close the dialog using

该对话框显示正常,但是当我尝试使用

SP.UI.ModalDialog.commonModalDialogClose(SP.UI.DialogResult.OK, someValue)

SP.UI.ModalDialog.commonModalDialogClose(SP.UI.DialogResult.OK, someValue)

I get an error that says

我收到一个错误提示

Unable to get value of the property 'OK': object is null or undefined

无法获取属性“OK”的值:对象为空或未定义

回答by Paul

A quick/hacky workaround would be to use 1 which stands for SP.UI.DialogResult.OK

一个快速/hacky 的解决方法是使用 1 代表 SP.UI.DialogResult.OK

Thanks, I was able to get this to work using numbers instead of SP.UI.DialogResult.OK.

谢谢,我能够使用数字而不是 SP.UI.DialogResult.OK 让它工作。

For example...

例如...

SP.UI.ModalDialog.commonModalDialogClose(0,'Canceled the dialog.');is like using SP.UI.DialogResult.cancel

SP.UI.ModalDialog.commonModalDialogClose(0,'Canceled the dialog.');就像使用 SP.UI.DialogResult.cancel

SP.UI.ModalDialog.commonModalDialogClose(1,'Yay Success!');is like using SP.UI.DialogResult.OK

SP.UI.ModalDialog.commonModalDialogClose(1,'Yay Success!');就像使用 SP.UI.DialogResult.OK

SP.UI.ModalDialog.commonModalDialogClose(-1,'Uh oh... Error');is like using SP.UI.DialogResult.invalid

SP.UI.ModalDialog.commonModalDialogClose(-1,'Uh oh... Error');就像使用 SP.UI.DialogResult.invalid

回答by Stefan

You need to include the SharePoint JS file SP.UI.Dialog.json your "dialog page".

您需要在“对话框页面”中包含 SharePoint JS 文件SP.UI.Dialog.js

<SharePoint:ScriptLink Name="SP.UI.Dialog.js" runat="server" />

or

或者

<script src="/_layouts/SP.UI.Dialog.js" type="text/javascript"></script>

A quick/hacky workaround would be to use 1which stands for SP.UI.DialogResult.OK.

一个快速/hacky 的解决方法是使用1which 代表SP.UI.DialogResult.OK.