显示项目的附件链接正在减慢我的列表视图导航 [英] show the items' attachment links is slowing down my list view navigations

查看:66
本文介绍了显示项目的附件链接正在减慢我的列表视图导航的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理自定义列表,并且允许用户将文件附加到项目上..现在的问题是,在内置列表视图中,附件字段将仅显示一个图标,指示是否项目是否具有附件,而不是显示实际 附件链接,如下所示:-

I am working on a custom list, and i allow users to attach files to the items.. now the problem is that inside the built-in list view the attachment field will just render an icon, indicating if the item have an attachment or not instead of showing the actual attachments links, as follow:-

因此,我编写了以下JSLINK并将其链接到列表视图Web部件:-

So i wrote the following JSLINK and link it to the list view web part:-

(function () {  

    var linkFieldContext = {};

    linkFieldContext.Templates = {};

    linkFieldContext.Templates.Fields = {

        "Attachments": { "View": AttachmentsFieldTemplate }
    };

    SPClientTemplates.TemplateManager.RegisterTemplateOverrides(linkFieldContext);

})();



function AttachmentsFieldTemplate(ctx) {
    var listItemId = ctx.CurrentItem.ID;
    var listName = ctx.ListTitle;       
    return getAttachments(listName, listItemId);
}

function getAttachments(listName,listItemId) {

    var url = _spPageContextInfo.webAbsoluteUrl;
    var webServiceUrl = url + "/_api/web/lists/getbytitle('" + listName + "')/items(" + listItemId + ")/AttachmentFiles";
    var attachHtml = "";

    var xmlhttp = new XMLHttpRequest();
    xmlhttp.open('GET', webServiceUrl , false);
    xmlhttp.setRequestHeader('accept','application/json;odata=verbose');
    xmlhttp.onreadystatechange = function() {
        if (xmlhttp.readyState == 4) {
            if(xmlhttp.status == 200) {
                var data = JSON.parse(xmlhttp.responseText);
                for(var i = 0; i < data.d.results.length; i++) {
                    attachHtml += "<a href='" + data.d.results[i].ServerRelativeUrl + "'>" + data.d.results[i].FileName + "</a>";
                    if (i != data.d.results.length - 1) {
                        attachHtml += "<br/>";
                    }                
                }               
             }
        }
    };
    xmlhttp.send(null);   

    return attachHtml;
}


现在我在附件列中正确地获得了附件链接,但是我面临的问题是列表导航和列表视图呈现变得非常慢.将要 放慢导航速度..但是上述JSLINK可以以某种方式进行改进吗,因此不影响性能?还是我可以依靠内置功能来实现此目的,而不是像我目前正在编写的那样编写自定义JSLINK?


now i got the attachment links correctly inside the attachment column, but the problem i am facing is that the list navigation and the list view rendering became very slow.. i do understand that the JSLINK will do a REST call to query the list items which will slow down the navigation.. but can the above JSLINK be improved in a way or another so it does not affect performance ? or can i rely on built-in capabilities to achieve this instead of writing a custom JSLINK as i am currently doing ?

推荐答案

你好

我不确定是否可以提高您的请求速度.您是否有可能不显示负载上的所有附件,而仅当人们单击/悬停附件图标时显示?

I'm not sure it would be possible to increase the speed of you request. Is it possible that you don't show all the attachments on the load but only when people click/hover the attachment icon?

这篇文章讨论了这样做的解决方案:  https://blog.ithinksharepoint.com/2014/11/17/sharepoint-2013online-attachment-viewer-enhancement/ 

This post talk about a solution doing this : https://blog.ithinksharepoint.com/2014/11/17/sharepoint-2013online-attachment-viewer-enhancement/ 

也许可以帮助您


这篇关于显示项目的附件链接正在减慢我的列表视图导航的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆