使用代码我在sharepoint页面的脚本编辑器中使用它。我想显示一条消息,指出"未找到结果"。我一遍又一遍地试过而且没有显示出来。
<!-- Style -->
<style type="text/css">
.item-name-clickable{
font-size:1.1em;
background-color: #c7e0f4;
padding:2px 5px;
margin-top:2px;
cursor:pointer;
}
.item-narrative{
display: none;
border-right:3px #c7e0f4 solid;
border-bottom:3px #c7e0f4 solid;
border-left:3px #c7e0f4 solid;
padding:3px;
}
</style>
<!-- HTML placeholder -->
<div id="COTPTEST_placeholder"></div>
<!-- Script -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script type="text/javascript">
function getCOTPItems(){
var date = new Date(), dateISO = "";
date.setDate(date.getDate()-1);
dateISO = String(date.getFullYear()) + "-" + String(date.getMonth()+1) + "-" + String
(date.getDate()) + "T00:00:00Z";
var endpoint = "https://intelshare.intelink.gov/sites/sccnola/COTP/_api/web/lists/getbytitle
('COTP')/items?$filter=(Created ge datetime'"+dateISO+"')&$orderby= Created desc";
jQuery.ajax({
url: endpoint,
method: "GET",
headers: {
"accept": "application/json; odata=verbose",
"content-type": "application/jsom;odata=verbose",
"X-RequestDigest": document.getElementById("__REQUESTDIGEST").value
}
}).done(function (data) {
var b = [];
jQuery.each(data.d.results,function(i,item){
b.push("<div class='item-name-clickable' onclick='jQuery(this).next().slideToggle
(100);'>"+item.name+"</div>");
b.push("<div class='item-narrative'>"+item.Narrative+"</div>");
});
jQuery("#COTP_placeholder").html(b.join(""));
}).fail(function (err) {
jQuery("#COTP_placeholder").html(JSON.stringify(err));
});
}
// Call function
getCOTPtems();
</script>
</code>