我正在尝试为SharePoint站点的用户开发仪表板主页,并且作为此页面的一部分,我正在利用AJAX对站点内的其他列表进行API调用。
在我的子网站管理员帐户的上下文中,AJAX调用是在没有问题的情况下进行的,并且JS正确地应用了HTML。
用户需要什么样的权限才能使以下JavaScript正常工作?
function taskCheckListFill(){
callCurrentUser(function(userEmail){ //pulls the userEmail var from callCurrentUser into this function
//alert(userEmail);
var TodayDate = new Date(); //returns TodayDate var as the current Date from Date() method
var siteUrl = _spPageContextInfo.webAbsoluteUrl; //returns the current sharepoint site url
var dPeriod = TodayDate.getMonth(); //+1 as getMonth() method returns an index, thus Feb equals 1 and must add 1
var sYear = TodayDate.getYear()+1900; //+1900 brings the year back to standard readable format this JS method bases years off of starting at 1900
$.ajax({
url: siteUrl + "/_api/web/lists/GetByTitle('Month-End Task Checklist')/items?$filter=Period eq "+ dPeriod + " and Year eq " + sYear + " &$top=1000",
type: "GET",
contentType: "application/json;odata=verbose",
data: "",
headers: {
"Accept": "application/json;odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val()
},
success: function (data){
var sum = 0;
var jsonData = data.d.results
console.log(jsonData.length);
console.log(jsonData[0]);
console.log(jsonData[0].Area);
var step; //initializes the loop count var
//variables below represent the status count vars placed into the grph and
var tasksNotStartedCount = 0;
var tasksInProgressCount = 0;
var tasksWaitingCount = 0;
var tasksCompletedCount = 0
//loop is to go from 0 to number of items in list for EVERYONE in the specified period and year
for (step = 0; step < jsonData.length; step++){
console.log(jsonData[step].Title);
if(jsonData[step].Assigned_x0020_To_x002d_Email_x0 == userEmail){
$('#myTaskChecklistTable > tbody:last').append('<tr><td>'+ jsonData[step].Title +'</td><td>'+ jsonData[step].TaskID +'</td><td>'+ jsonData[step].Due_x0020_Date+'</td><td>'+ jsonData[step].Status +'</td></tr>')
};
if(jsonData[step].Assigned_x0020_To_x002d_Email_x0 == userEmail && jsonData[step].Status == "Not Started"){
tasksNotStartedCount ++
};
if(jsonData[step].Assigned_x0020_To_x002d_Email_x0 == userEmail && jsonData[step].Status == "In Progress"){
tasksInProgressCount ++
};
if(jsonData[step].Assigned_x0020_To_x002d_Email_x0 == userEmail && jsonData[step].Status == "Waiting on someone else"){
tasksWaitingCount ++
};
if(jsonData[step].Assigned_x0020_To_x002d_Email_x0 == userEmail && jsonData[step].Status == "Completed"){
tasksCompletedCount ++
};
//console.log(jsonData[step].Area);
};
document.getElementById("taskCheckListCount_GBSHOME").innerHTML = tasksCompletedCount + "/" + (tasksNotStartedCount +tasksInProgressCount+tasksWaitingCount+tasksCompletedCount) + " completed";
console.log("Not started count is equal to " + tasksNotStartedCount );
console.log("In Progress count: " + tasksInProgressCount);
console.log("Tasks waiting on someone else count: " + tasksWaitingCount);
console.log("Completed count is equal to " + tasksCompletedCount);
pieChartCall1(tasksNotStartedCount, tasksInProgressCount, tasksWaitingCount, tasksCompletedCount);
},
error: function (data) {
console.log(data.responseText);
}
});
});
};
您可以添加用户“读取”权限级别,以便他们可以访问列表数据。
通过编辑ROLES(不是分配给角色的组)的权限解决了这个问题。
需要激活的权限是“使用远程接口 - 使用SOAP,Web DAV,客户端对象模型或SharePoint Designer界面来访问网站”。
我通过导航到站点内容 - >站点权限 - >单击权限级别 - >单击要编辑的特定权限级别超链接来访问这些设置。