我需要在其他列表项的SharePoint页面中填充下拉列表。我想从其他列表项中下拉列表项。请帮忙,谢谢。我不知道如何开始。
答案 0 :(得分:0)
您需要使用jQuery从列表中获取项目。请按照下面的代码示例从列表中获取项目: 请参阅下面的示例,其中我们填充DropDown(选择控件),其中列表项值从Sharepoint列表中获取,其中FieldName等于Alpha。您可以通过修改CAML查询来修改结果。下面代码中的变量是要用ListName,SiteName等替换的名称。
var soapEnv = "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'> \
<soapenv:Body> \
<GetListItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'> \
<listName>SPListName</listName> \
<viewFields> \
<ViewFields> \
<FieldRef Name='Title' /> \
</ViewFields> \
</viewFields> \
<query> \
<Query> \
<OrderBy> \
<FieldRef Name='Title'/> \
</OrderBy>\
<Where> \
<Eq> \
<FieldRef Name='FieldName'/> \
<Value Type='Text'>"+ "Alpha" +"</Value> \
</Eq> \
</Where> \
</Query> \
</query> \
</GetListItems> \
</soapenv:Body> \
</soapenv:Envelope>";
$.ajax({
url: "http://servername/sitename/_vti_bin/lists.asmx",
type: "POST",
dataType: "xml",
data: soapEnv,
complete: processResult,
contentType: "text/xml; charset=\"utf-8\""
});
});
//以下函数将从List获取的数据填充到下拉控件。
function processResult(xData, status) {
$(xData.responseXML).find("z\\:row").each(function() {
$("select[title='SelectControlID']").append("<option value='" + $(this).attr("ows_ID") + "'>" + $(this).attr("ows_Title") + "</option>");
});
}