약속 된 정보를 사용하여 현재 로그인 한 사용자와 SharePoint의 목록 필드를 비교하려고합니다.Ajax 약속 안 함
function compareCurrentUserWithListObject() {
var userProp = this._userProfileProperties;
var userName = userProp.get_userProfileProperties()['UserName'];
return this._list.filter(function (element, index, array) {
var promise = jQuery.ajax({
url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/GetUserById(" + element.user.get_lookupId() + ")",
type: "GET",
headers: { "Accept": "application/json;odata=verbose" }
});
promise.done(function(data) {
return (data.d.Email.indexOf(userName) > -1);
});
});
}
function init() {
var userArray = this.compareCurrentUserWithListObject();
userArray.done(function(res) {
if (res.length > 0) {
//Do some stuff after compare...
}
});
}
여기에서 올바른 .done을 사용하고 있는지 확실하지 않습니다. 누군가 나를 도울 수 있습니까?
편집 :
근무 코드 :
function compareCurrentUserWithListObject() {
var userProp = this._userProfileProperties;
var userName = userProp.get_userProfileProperties()['UserName'];
return this._list.filter(function (element, index, array) {
var promise = jQuery.ajax({
url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/GetUserById(" + element.user.get_lookupId() + ")",
type: "GET",
headers: { "Accept": "application/json;odata=verbose" }
});
promise.done(function(data) {
return (data.d.Email.indexOf(userName) > -1);
});
return promise;
});
}
function init() {
var userArray = this.compareCurrentUserWithListObject();
if (userArray.length > 0) {
//Do some stuff after compare...
}
}
무엇을 작동하지 않습니다? – melancia
숫자를 반환해야 data.d.Email.indexOf (userName)에 일치하는 항목이 있지만 userArray.done에는 아무 것도 표시되지 않습니다. – Robin
작업 코드가 실제로 작동하는지 확인 하시겠습니까? 왜냐하면'userArray.length'는'> 0' ** 항상 **입니다. – dfsq