我正在使用Sharepoint2013。我只是为用户的get属性编写了基本的javascript代码。这不是我能应付的。
<script>
$(function(){
var date1 = moment().format("MM/DD/YYYY");
var requestUri = _spPageContextInfo.webAbsoluteUrl + "/_api/Web/Lists/GetByTitle('Kisiye Ozel Duyuru')/Items?$select=Title,ID,Duyuru_x0020_Atanan/Title,Duyuru_x0020_Aciklama&$expand=Duyuru_x0020_Atanan/Id";
$.ajax({
url: requestUri,
type: "GET",
headers: {
"accept":"application/json; odata=verbose"
},
success: onSuccess,
error: onError
});
function onSuccess(data) {
if(data.d.results.length > 0){
var objItems = data.d.results;
var atanan = objItems[1].Duyuru_x0020_Atanan.Title;
var baslik = objItems[1].Title;
var aciklama = objItems[1].Duyuru_x0020_Aciklama;
console.log(data.d.results);
console.log(GetUserinfo());
Bildirim(atanan,baslik,aciklama);
}
}
function onError(error) {
alert('Bildirimde bir hata var !');
}
});
function Bildirim (atanan, baslik, aciklama){
swal({
title: '<strong>Sayın '+atanan+'</u></strong>',
html:
'<b>'+baslik+'</b>, ' +
''+aciklama+'' +
'',
imageUrl: 'http://intranet.uma.com.tr/SiteAssets/Duyuru.png',
showCloseButton: false,
showCancelButton: false,
focusConfirm: false,
confirmButtonText:
'<i class="fa fa-thumbs-up animated wow bounceInLeft"></i> Tamam!',
confirmButtonAriaLabel: 'Tamam!',
cancelButtonText:
'<i class="fa fa-thumbs-down"></i>',
cancelButtonAriaLabel: 'Thumbs down',
});
}
let GetUserinfo = function () {
// Wait until SP.JS has loaded before calling getWebUserData
ExecuteOrDelayUntilScriptLoaded(getWebUserData, "sp.js");
}
var context = null;
var web = null;
var currentUser = null;
var userGroups = null;
var displayGroups = null;
function getWebUserData() {
context = new SP.ClientContext.get_current(); // Get the current user
web = context.get_web(); // Get the current web
currentUser = web.get_currentUser(); // Get the current user
context.load(currentUser); // Load the current user
context.executeQueryAsync(kaka, onFailureMethod);
}
let kaka = function () {
/*/alert('User name:' + currentUser.get_title() + '\n Login Name:' + currentUser.get_loginName());/*/
var myJSON = JSON.stringify(currentUser);
var userTitle =currentUser.get_title();
return userTitle;
}
function onFailureMethod(sender, args) {
alert('request failed ' + args.get_message() + '\n' + args.get_stackTrace());
}
</script>
这是我的代码。我试过console.log(GetUserinfo)它返回未定义。但是我在我的kaka函数中写了'alert(GetUserinfo())',它可以正常工作。我只需要获取价值或财产。我哪里错了?
答案 0 :(得分:0)
这里是我的解决方案,我正在使用SPservice.js库,并在我的arraylist和return list中添加属性;
function UserProperties() {
myGroups = new Array();
var Name = $().SPServices.SPGetCurrentUser({
fieldName: ["Title"],
debug: false
});
myGroups.push(Name);
var Email = $().SPServices.SPGetCurrentUser({
fieldName: ["EMail"],
debug: false
});
myGroups.push(Email);
var Picture = $().SPServices.SPGetCurrentUser({
fieldName: ["Picture"],
debug: false
});
myGroups.push(Picture);
console.log(myGroups);
return myGroups;
}