0

你好堆栈溢出社区...

感谢您迄今为止提供的所有帮助,即使我从未在此站点上发布过。我是一个初学者......所以这意味着我已经开始工作的大部分东西都是在尝试将一个方形钉子推入一个圆孔太多次之后数不清,直到最后边缘磨损到它实际上适合它...

无论如何...由于 SharePoint 的 Today() 问题以及需要将数据与当前日期/时间进行比较,我一直在努力编写自己的代码并在我想要的 SharePoint 网站中显示数据也有访问权限。

到目前为止,我的一切都按预期工作,但有一个小缺陷......

即使我可以在两个值之间进行比较,我也无法弄清楚如何计算值。我相信这与如何从 SharePoint 列表行中检索数据并附加到 HTML 表有关。

相关部分代码如下:

$(document).ready(function () {
    $().SPServices({
    operation: "GetListItems",
    async: false,
    CAMLRowLimit: 20,
    listName: "Announcements",
    completefunc: FirstFunc
    });
});

function FirstFunc(xData, Status) {
var index = 0;
$documentListtable = $("#tableFirstFunc");

$(xData.responseXML).find("z\\:row, row").each(function () {


var LOTOSPLink =$(this).attr("ows_LOTODocLink");
var _Title = $(this).attr("ows_Title");
var ahref = "<a href='" + LOTOSPLink + "'>";
var anchor = "</a>"
var Titles = ahref + _Title + anchor

    //Start of AReview

var _AReview = $(this).attr("ows_AReview");
var astartDateTime = $(this).attr("ows_AReview");
var astartDate = $(this).attr("ows_AReview").split(" ")[0];
var astartTime = $(this).attr("ows_AReview").split(" ")[1];

var astartDateParts = astartDate.split("-");
var aSPDYear = astartDateParts[0];
var aSPDMonth = astartDateParts[1];
var aSPDDay = astartDateParts[2];

var aSPDJoin = aSPDMonth+'/'+aSPDDay+'/'+aSPDYear;

var astartTimeParts = astartTime.split(":");
var aSPTHour = astartTimeParts[0];
var aSPTMin = astartTimeParts[1];
var aSPTSec = astartTimeParts[2];

    //Combine SharePoint Date & Time split parts back together in JS Date Object 
                //format and than convert to millisecons to compare dates

        var aReviewGraphic = ""
  if(aSPDTValue === 18000000) {
    aReviewGraphic="<img src="sites/Somesite/NAGlassyButton20.png>";
    }
    else if(aSPDTValue >= firstDCMonth && aSPDTValue < lastDCMonth) {
    aReviewGraphic="<img src="/sites/Somesite/GreenButtNew20.png>";
    }
    else if(aSPDTValue >= firstDCYear && aSPDTValue < firstDCMonth) {
    aReviewGraphic="<img src="/sites/Somesite//GreenButtOld20.png>";
    }
    else if(aSPDTValue < firstDCYear) {
    aReviewGraphic="<img src="/sites/Somesite/RedButt20.png>";
    }

var $row = $("#templates").find(".row-template").clone();

$row.find(".Titles").html(Titles);
$row.find(".aReviewGraphic").html(aReviewGraphic);
$row.find(".bReviewGraphic").html(bReviewGraphic);
$row.find(".cReviewGraphic").html(cReviewGraphic);
$row.find(".dReviewGraphic").html(dReviewGraphic);
$row.find(".NewModiDReviewGraphic").html(NewModiDReviewGraphic);

$documentListtable.append($row);

});

}

我正在按预期更改表格中的图形,数据正在按需要显示......但我无法弄清楚如何执行计数。似乎是一次读取一行,并一个接一个地放入 HTML 表中,并且所有比较都是逐行完成的。我这么说是因为从共享点列表中提取的每一行数据都会触发我的警报(消息)。

有没有办法将这些数据存储在本地数组中......当然有一些方法可以做到这一点,但我对此很陌生,我什至不知道要问的正确问题......

此外,if 语句中的 18000000 是 1970 年 1 月 1 日的测试日期,因为我发现共享点列表中的任何空白字段都会导致查询退出,然后返回任何行。我的解决方案是使用 1/1/1970 作为默认值,并使用它与将字段留空相同。我确信这是解决一个很容易解决的问题的粗略方法,但这是我能想到的。

任何帮助将不胜感激......史蒂夫

4

1 回答 1

0

我试图理解...我的建议是将所有 html 存储到一个变量中,然后将代码注入表中。

// somewhere you should have your HTML code
// <table id="templates"></table>

$(document).ready(function () {
  $().SPServices({
    operation: "GetListItems",
    async: false,
    CAMLRowLimit: 20,
    listName: "Announcements",
    completefunc: FirstFunc
  });
});

function FirstFunc(xData, Status) {
  var index = 0;
  $documentListtable = $("#tableFirstFunc");
  // create a variable where to store the html code
  var htmlData = "";
  // go thru the data received by the query
  $(xData.responseXML).find("z\\:row, row").each(function () {
    // we look at one row
    var LOTOSPLink =$(this).attr("ows_LOTODocLink");
    var _Title = $(this).attr("ows_Title");
    var ahref = "<a href='" + LOTOSPLink + "'>";
    var anchor = "</a>"
    var Titles = ahref + _Title + anchor

    //Start of AReview
    var _AReview = $(this).attr("ows_AReview");
    var astartDateTime = $(this).attr("ows_AReview");
    var astartDate = $(this).attr("ows_AReview").split(" ")[0];
    var astartTime = $(this).attr("ows_AReview").split(" ")[1];

    var astartDateParts = astartDate.split("-");
    var aSPDYear = astartDateParts[0];
    var aSPDMonth = astartDateParts[1];
    var aSPDDay = astartDateParts[2];

    var aSPDJoin = aSPDMonth+'/'+aSPDDay+'/'+aSPDYear;

    var astartTimeParts = astartTime.split(":");
    var aSPTHour = astartTimeParts[0];
    var aSPTMin = astartTimeParts[1];
    var aSPTSec = astartTimeParts[2];

    //Combine SharePoint Date & Time split parts back together in JS Date Object 
    //format and than convert to millisecons to compare dates

    var aReviewGraphic = "";
    // I don't understand why you use this variable that hasn't been initialized...
    if (aSPDTValue === 18000000) {
      aReviewGraphic='<img src="sites/Somesite/NAGlassyButton20.png>';
    }
    else if(aSPDTValue >= firstDCMonth && aSPDTValue < lastDCMonth) {
      aReviewGraphic='<img src="/sites/Somesite/GreenButtNew20.png>';
    }
    else if(aSPDTValue >= firstDCYear && aSPDTValue < firstDCMonth) {
      aReviewGraphic='<img src="/sites/Somesite//GreenButtOld20.png>';
    }
    else if(aSPDTValue < firstDCYear) {
      aReviewGraphic='<img src="/sites/Somesite/RedButt20.png>';
    }

    htmlData += '<tr><td class="Titles">'+Titles+'</td><td class="aReviewGraphic">'+aReviewGraphic+'</td><td class="bReviewGraphic">'+bReviewGraphic+'</td><td class="cReviewGraphic">'+cReviewGraphic+'</td><td class="dReviewGraphic">'+dReviewGraphic+'</td><td class="NewModiDReviewGraphic">'+NewModiDReviewGraphic+'</td></tr>';

    // you can increment your index if you want
    index++;
  });

  alert("There are "+index+" rows");
  // add the HTML data into the table
  $documentListtable.append(htmlData);
}
于 2013-05-16T15:59:15.323 回答