我正在尝试从 SharePoint 列表(“Winners”)中读取并使用内容编辑器将其显示在页面上。这听起来很简单,但由于某种原因,我很难做到这一点。我的代码如下:
<style type="text/css">
h4{
color: red
}
table{
border: #ccc solid 2px;
border-radius: 3px;
}
</style>
<script src="/_layouts/1033/FH/jquery-1.7.min.js" type="text/javascript"></script>
<script type="text/javascript" src="/_layouts/1033/FH/jquery.SPServices-0.7.1a.js">
</script>
<script type="text/javascript">
$(document).ready(function(){
GetWinners();
}):
//getWinners Function starts here.
function GetWinners(){
//Variables to store information.
var method = "GetListItems";
var list = "Winners";
var fieldsToRead = "<ViewFields>" +
"<FieldRef Name='Title' />" +
"<FieldRef Name='Picture' />" +
"<FieldRef Name='Text' />" +
"</ViewFields>";
var query = "<Query>" +
"<Where>" +
"<Neq>" +
"<FieldRef Name='ID'/><Value Type='Number'>0</Value>" +
"</Neq>" +
"</Where>" +
"<OrderBy>" +
"<FieldRef Name='Title'/>" +
"</OrderBy>" +
"</Query>";
//SPServices call where we pass the above variables.
$().SPServices({
operation: method,
async: false,
listName: list,
CAMLViewFields: fieldsToRead,
CAMLQuery: query,
completefunc: function (xData, Status){
$(xData.responseXML).SPFilterNode("z:row").each(function() {
var name = ($(this).attr("ows_Title"));
var pictureUrl = ($(this).attr("ows_Picture"));
var caption = ($(this).attr("ows_Text"));
AddRowToTable(name, pictureUrl, caption);
});
}
});
}//End
//Function to add content on the page starts here.
function AddRowToTable(name, pictureUrl, caption){
$("#winnersTable").append("<tr align:'middle'>" +
"<td><img src='"+ pictureUrl + "'/><br><h4>" + name + "</h4><br><p>" + caption + "</p></td>" +
"</tr>");
}
</script>
<!-- table where the winners would go -->
<div>
<table id="winnersTable"></table>
</div>
如果有人能指出我做错了什么,那将是一个很大的帮助。我的字段和列表的所有内部名称都是正确的,所以这不是问题。当我尝试从内容编辑器引用它时,也许我错过了。我希望我解释得对,但如果有任何问题,请告诉我。
问候,