这很简单,你需要在“listName”下面声明一个“CAMLQuery”、“CAMLRowLimit”和“CAMLViewFields”,我将用下一个代码示例来解释:
您可以从您的列表视图中获取您的 CAMLQuery,在 sharepoint Designer 打开一个表单,我打开我的视图列表 anuncio.aspx 并找到下一个代码:
<View Name="your list name">
<Query>
<OrderBy>
<FieldRef Name="Title" Ascending="FALSE"/>
</OrderBy>
</Query>
<ViewFields>
<FieldRef Name="Title"/>
<FieldRef Name="Body"/>
<FieldRef Name="Expires"/>
</ViewFields>
<RowLimit Paged="TRUE">30</RowLimit>
<Toolbar Type="Standard"/>
</View>
然后根据您的需要或对视图列表的查询,在您的 JavaScript 代码中拆分查询 caml,
var fields ="<ViewFields>"+
"<FieldRef Name='Title'/>"+
"<FieldRef Name='Body'/>"+
"<FieldRef Name='Expires'/>"+
"</ViewFields>";
var query = "<Query>"+
"<OrderBy>"+
"<FieldRef Name='Modified' Ascending='FALSE'/>"+
"</OrderBy>"+
"</Query>";
在变量中设置 CAMLQuery 后,修改您的脚本:
$(document).ready(function() {
$().SPServices({
operation: "GetListItems",
async: false,
listName: "Your List name",
CAMLViewFields: fields,
CAMLQuery: query,
completefunc: function (xData, Status) {
$(xData.responseXML).SPFilterNode("z:row").each(function() {
var liHtml = "<tr> <td>" + $(this).attr("ows_Title") + "</td> </tr>";
$("#tasksUL").append(liHtml);
});
}
});
});
</script>
<table id="tasksUL"/>