i just want to know: Is there any way to get a SharePoint user using JavaScript/jQuery from default sharepoint-2010 user profile DB?
My requirement is to form an array of all SharePoint site users (user name) and use this array in a java function (that run behind the page at client side ) as a data source for a SPServices function.
Please provide any feasible solution or any other approach for building the array for JavaScript.
thanks
There are two ways to do it:
Use client object model (OM) for ECMAScript:
SharePoint 2010: Client Object Model for JavaScript (ECMAScript)
The first article explains how to retrieve information about SharePoint users using OM and the second one shows how to use OM from JavaScript - you have to combine appropriate pieces of code.
Call appropriate method from the UserGroup service (eg GetAllUserCollectionFromWeb
or GetUserCollection
) using jQuery:
Using SPServices from codeplex:
<script type="text/javascript">
$(document).ready (function() {
$().SPServices({
operation: "GetListItems",
async: true,
listName: "User Information List",
CAMLViewFields: "<ViewFields>" +
"<FieldRef Name='Title' />" +
"</ViewFields>",
completefunc: AttachMembersAutoComplete
});
});
function AttachMembersAutoComplete(xmlResponse) {
var domElementArray = $( "[nodeName=z:row]", xmlResponse.responseXML );
var dataMap = domElementArray.map(function() {
return {
value: $(this).attr('ows_Title'),
};
});
var data = dataMap.get();
$("input#inputMembersAutoComplete").autocomplete({
source: data,
select: function(e, ui){
var tmpHTML = ui.item['value'];
$("#person_info").html(tmpHTML);
}
});
}
</script>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.