sharepoint 使用listform.aspx 显示页面的增加,修改和显示页面

当我们做sharepoint的项目时候,有时候需要调用列表项自己带的新增,修改和显示界面,那么如何做呢?

方法一:使用核心的方法

首先我们需要知道列表项的网站集地址,网站地址,列表ID(GUID)还有就是ContentTypeID和每一项的ID,一般ContentTypeID是不变得,只需要复制即可(除非你重新建立了列表定义),不同的页面,PageType来取决于定位具体页面

显示页面地址:PageType = 4

<a target="_self" href="http://siteurl/weburl/_layouts/listform.aspx?PageType=4&ListId={60EDAB82-D9EF-4F89-BCEB-D9B287BDCC96}&ContentTypeID=0x01020004D023775B015F43930EAF26E5B8AD35&ID=1">Gavin Yang</a>

编辑页面地址:PageType = 6

<a target="_self" href="http://siteurl/weburl/_layouts/listform.aspx?PageType=6&ListId={60EDAB82-D9EF-4F89-BCEB-D9B287BDCC96}&ContentTypeID=0x01020004D023775B015F43930EAF26E5B8AD35&ID=1">Gavin Yang</a>

新增页面地址:PageType = 8

<a target="_self" href="http://siteurl/weburl/_layouts/listform.aspx?PageType=8&ListId={60EDAB82-D9EF-4F89-BCEB-D9B287BDCC96}&RootFolder=">Gavin Yang</a>

特别说明:新增的RootFolder参数不需要知道,这个如果是有下级目录才会用到,我们现在只考虑单一列表

方法二:使用自定义的方法

我们可以使用SharePoint自己带的对话框来创建自己的对话框,可以使用标准的连接,例如,你可以右击SharePoint弹出的对话框点击属性来发现这些连接:

  • 显示窗体: http://siteurl/weburl/test/Lists/Gavin/DispForm.aspx?ID=1
  • 编辑窗体: http://siteurl/weburl/test/Lists/Gavin/EditForm.aspx?ID=1
  • 新建窗体: http://siteurl/weburl/test/Lists/Gavin/NewForm.aspx

然后使用SharePoint提供的窗体函数openDialog来展示

function openDialog(openURL) {
    SP.UI.ModalDialog.showModalDialog({
        url: openURL,
         500,
        height: 400,
        title: "我的自定义对话框"
    });
}
有本事别点我

这样一来,我们就可以在界面上来调用他

<a href="javascript:openDialog('http://siteurl/weburl/test/Lists/Gavin/DispForm.aspx?ID=1')">打开对话框</a>

以此类推,如果你想只需要id来访问你的列表项,可以这样写:

function openDialog(openID) {
    SP.UI.ModalDialog.showModalDialog({
        url: 'http://siteurl/weburl/test/Lists/Gavin/DispForm.aspx?ID=' + openID,
         500,
        height: 400,
        title: "我的自定义对话框"
    });
}
有本事别点我

我们就能在界面上这样调用:

<a href="javascript:openDialog(1)">打开对话框</a>

希望对学习sharepoint的朋友有帮助,这是一篇国外的文章,但是国内没有类似的,我就翻译了一下,加上一些自己的理解,和项目中的应用,把这些写了出来,谢谢!

原文地址:https://www.cnblogs.com/yangmengyi/p/3376324.html