简体   繁体   中英

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. 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. 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:

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. You may need to play around with it though to handle timezones properly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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