简体   繁体   English

添加新项目已加载,指示器图像从 SharePoint 中的文件夹加载到网页后添加到项目

[英]Adding a New Item has been loaded, Indicator Image to an Item after its been Loaded to a webpage from a Folder in SharePoint

I added a feature to my script that adds files from a folder in a SharePoint library onto a webpage, to include an indicator showing this is a new item.我向脚本添加了一项功能,可将 SharePoint 库中文件夹中的文件添加到网页上,以包含一个指示符,显示这是一个新项目。 I accomplished this using the provide script example.我使用提供脚本示例完成了此操作。 But what I'm having trouble figuring out is how to extend the time pass the upload date and current date condition/connection.但是我无法弄清楚如何延长上传日期和当前日期条件/连接的时间。

In my script I added a conditional statement stating if the file upload date equals the current date then show the new indicator image, if not then do not show then new indicator image.在我的脚本中,我添加了一个条件语句,说明文件上传日期是否等于当前日期,然后显示新的指标图像,如果不是,则不显示新的指标图像。 Once the upload passes the current date the image indication is removed.一旦上传超过当前日期,图像指示就会被删除。

Any ideas on how I can extend the new indicator 5 days past the upload/current date statement.关于如何在上传/当前日期声明后 5 天延长新指标的任何想法。 I hope this is not too confusing to grasp.我希望这不会太混乱而难以理解。 Any help would be greatly appreciated.任何帮助将不胜感激。

getFilesFromFolder("/sites/dcsa/ep/New%20Pages/resources").done(function(data){
    $.each(data.d.results,function(i,item){

    if (item.TimeCreated.split('T')[0] == curday('-')) {

    $("#column1").append('<li class="linkData" style="padding-left: 10px; padding-right: 10px;"><a href="' + 'https://intelshare.intelink.gov' +     item.ServerRelativeUrl + '" target="_blank"><img class="newArrow" style="width: 60px; position: relative; right: 5px; top: 0px;"src="../SiteAssets/SitePages/Test Page/icons/arrow-with_new2.gif" alt="logo">' + item.Name.replace(/\.[^/.]+$/, "") + " - "   + item.TimeCreated.split('T')[0]  + '</a></li>');

        } else {

    $("#column1").append('<li class="linkData" style="padding-left: 10px; padding-right: 10px;"><a href="' + 'https://intelshare.intelink.gov' + item.ServerRelativeUrl + '" target="_blank">' + item.Name.replace(/\.[^/.]+$/, "")  + " - "   + item.TimeCreated.split('T')[0]  + '</a></li>');
}

   });
});

var curday = function(sp){
today = new Date();
var dd = today.getDate();
var mm = today.getMonth()+1; //As January is 0.
var yyyy = today.getFullYear();

if(dd<10) dd='0'+dd;
if(mm<10) mm='0'+mm;
return (yyyy+sp+mm+sp+dd);
};

function getFilesFromFolder(serverRelativeUrlToFolder){
  return $.ajax({
        url: _spPageContextInfo.webAbsoluteUrl + "/_api  web/GetFolderByServerRelativeUrl('"+serverRelativeUrlToFolder+"')/files", method: "GET",
        async:false,
        headers: { "Accept": "application/json; odata=verbose" }
       });
  }

You should try comparing Date objects instead of strings:您应该尝试比较 Date 对象而不是字符串:

var spDate = new Date(item.TimeCreated) //example: '2015-10-30T05:00:00Z'
var newTillDate = new Date();
newTillDate.setDate(newTillDate.getDate() + 5);
if(spDate <= newTillDate)
    //Show your new badge
else
    //Don't show your new badge

This should allow you to get rid of your curday function as well.这也应该允许您摆脱 curday 函数。 You may need to play around with it though to handle timezones properly.您可能需要使用它来正确处理时区。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM