我正在尝试从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>
如果有人能指出我做错了什么,这将是一个很大的帮助。我有所有字段的内部名称和列表正确,所以这不是问题。当我尝试从内容编辑器中引用它时,也许我错过了。我希望我解释了这一点,但如果有任何问题,请告诉我。
问候,
答案 0 :(得分:1)
行上有一个拼写错误:
}):
它应该是分号而不是冒号。
在CEWP中放置标记,但不是JavaScript代码
实际上这取决于,但这里仍有一些优点。首先,它涉及JavaScript代码库的维护和支持
使用公共图书馆
建议从母版页而不是Web部件中引用JavaScript库(如jQuery
)。