我有一个连接到SharePoint列表的ng-grid。当我尝试使用用户名填充字段时,SharePoint列表将返回ID号而不是用户名。
我有一个将ID转换为用户名的功能。
$scope.getUserName = function (user) {
var userId = user;
$Service.getUserById($scope, userId).done(function (data) {
$scope.userName = data.d.Title;
})
}
当我试图在" cellTemplate"中调用该函数时,我无法将ID变量发送到该函数。
$scope.gridOptions = {
loading: true,
enableSorting: true,
enableFullRowSelection: true,
enableRowHeaderSelection: false,
showGroupPanel: true,
columnDefs: [
{ name: "Admin", field: "AdministratorId" },
{ name: "User", field: "ApprovedById" },
{ name: "SuperUser", cellTemplate: '<div>{{grid.appScope.getUserName(<pass the id variable here>)}}{{grid.appScope.userName}}</div>' }
],
data: 'gridData'
};
如何从&#39; gridData&#39;中获取用户ID?并将其发送给我的函数?
更新:我正在使用的REST呼叫。
function getListItem(listName) {
var deferred = $.Deferred();
// query the list in the host web
var url = SPAppWebUrl + "/_api/SP.AppContextSite(@target)" +
"/web/lists/getbytitle('" + listName + "')/items?" +
"@target='" + SPHostUrl + "'";
$.ajax({
url: url,
type: "GET",
headers: { "Accept": "application/json;odata=verbose" }, // return data format
success: onGetEntriesSuccess,
error: onoDataCallFailure
});
function onGetEntriesSuccess(data) {
deferred.resolve(data.d);
}
function onoDataCallFailure(data, errorcode, errorMessage) {
deferred.reject("Error: " + errorMessage);
}
return deferred;}
答案 0 :(得分:0)
您的密码: cellTemplate:
'<div>{{grid.appScope.getUserName(**<pass the id variable here>**)}}{{grid.appScope.userName}}</div>'
像这样传递id:row.entity.Id //这个id在您的原始数据中可用。
现在代码是:
cellTemplate: '<div>{{grid.appScope.getUserName(row.entity.Id)}}{{grid.appScope.userName}}</div>'