在列表视图中放置附件的超链接(单击) [英] Placing a hyperlink (to click on) for an attachment in list view
问题描述
是否可以在列表视图中放置附件的超链接(单击),以自动拉出表单上的附件?
我们可以使用JSLINK和jQuery在SharePoint 2013中实现它.
步骤如下:
1.下载 jQuery API 并将js文件上传到网站资产文档库中.
2.将以下代码另存为js文件(showAttachments.js),并将其上传到站点资产文档库中.
(函数(){ //创建具有有关我们要更改的字段的上下文信息的对象输出渲染 var attachmentsFiledContext = {}; attachmentsFiledContext.Templates = {}; attachmentsFiledContext.Templates.Fields = { 附件":{视图":AttachmentsFiledTemplate} }; SPClientTemplates.TemplateManager.RegisterTemplateOverrides(attachmentsFiledContext); })(); //此功能提供列表视图的呈现逻辑 函数AttachmentsFiledTemplate(ctx){ var itemId = ctx.CurrentItem.ID; var listName = ctx.ListTitle; 返回getAttachments(listName,itemId); } //获取附件字段属性 函数getAttachments(listName,itemId){ var url = _spPageContextInfo.webAbsoluteUrl; var requestUri = url +"/_api/web/lists/getbytitle('""+ listName +"')/items("+ itemId +")/AttachmentFiles; var str =". //执行AJAX请求
.ajax({ 网址:requestUri, 类型:"GET", 标头:{"ACCEPT":"application/json; odata = verbose"; }, 异步:错误, 成功:功能(数据){ for(var i = 0; i< data.d.results.length; i ++){ str + ="< a href ='" + data.d.results [i] .ServerRelativeUrl +'" + data.d.results [i] .FileName +</a>"; 如果(i!= data.d.results.length-1){ str + =< br/>"; } } }, 错误:函数(err){ //alert(err); } }); 返回str; }3.编辑列表视图页面并编辑列表Web部件.转到其他-> JS链接.
4.将以下URL添加到JS Link文本框中.
〜site/SiteAssets/jquery-3.2.1.min.js |〜site/SiteAssets/showAttachments.js更多信息:
Hi,
We can use JSLINK and jQuery to achieve it in SharePoint 2013.
The steps as follows:
1.Download the jQuery API and upload the js file into the Site Assets Document Library.
2.Save the following code as a js file (showAttachments.js) and upload it into the Site Assets Document Library.
(function () { // Create object that have the context information about the field that we want to change it output render var attachmentsFiledContext = {}; attachmentsFiledContext.Templates = {}; attachmentsFiledContext.Templates.Fields = { "Attachments": { "View": AttachmentsFiledTemplate } }; SPClientTemplates.TemplateManager.RegisterTemplateOverrides(attachmentsFiledContext); })(); // This function provides the rendering logic for list view function AttachmentsFiledTemplate(ctx) { var itemId = ctx.CurrentItem.ID; var listName = ctx.ListTitle; return getAttachments(listName, itemId); } //get attachments field properties function getAttachments(listName,itemId) { var url = _spPageContextInfo.webAbsoluteUrl; var requestUri = url + "/_api/web/lists/getbytitle('" + listName + "')/items(" + itemId + ")/AttachmentFiles"; var str = ""; // execute AJAX request
.ajax({ url: requestUri, type: "GET", headers: { "ACCEPT": "application/json;odata=verbose" }, async: false, success: function (data) { for (var i = 0; i < data.d.results.length; i++) { str += "<a href='" + data.d.results[i].ServerRelativeUrl + "'>" + data.d.results[i].FileName + "</a>"; if (i != data.d.results.length - 1) { str += "<br/>"; } } }, error: function (err) { //alert(err); } }); return str; }3.Edit the list view page and edit the list web part. Go to Miscellaneous -> JS Link.
4.Add the following URL into the JS Link textbox.
~site/SiteAssets/jquery-3.2.1.min.js|~site/SiteAssets/showAttachments.jsMore information:
Best Regards,
Dennis
这篇关于在列表视图中放置附件的超链接(单击)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!