我的sooo接近我可以闻到终点线 -
当我的应用程序启动时,我的收获来自用户的登录信息(这是一个AngularJS SPA这样我就可以从spInfoContext中获取它很容易),并通过搜索名为itiUsers的列表来检查userId是否为用户。如果没有找到记录,我立即在itiUsers中创建新记录,然后为新用户提供一个表单,以输入我无法从SharePoint中获取的信息。该记录已正确创建。当promise返回时,我试图填充$ scope.current_user对象,以便它可以像返回用户一样 - 这就是我只需要有一个“我的首选项”表单。
但是,当记录创建后注销$ scope时,current_user为空。
这是我的控制功能(I值降低为简便起见,我试图大胆的问题行):
$.when(SharePointJSOMService.getCurrentUser())
.done(function(jsonObject){
if(jsonObject.d.results.length < 1 || jsonObject.d.results.newUser){
// new user
$.when(SharePointJSOMService.getLoggedInUser())
.done(function(jsonObject){
$scope.loggedInUser = jsonObject.d;
$scope.isNewUser = true;
$.when(SharePointJSOMService.createNewUser($scope))
.done(function(jsonObject){
**$scope.current_user.DisplayName = $scope.loggedInUser.Title;
console.log($scope);**
})
.fail(function(err){
$scope.prefPane = true;
console.info(JSON.stringify(err));
});
})
.fail(function(err){
$scope.prefPane = true;
console.info(JSON.stringify(err));
});
$scope.prefPane = true; // force preference pane
$scope.taskClose = true;
$scope.$apply();
} else {
// existing user
$scope.isNewUser = false;
$scope.prefPane = false; // hide preference pane
$scope.current_user = jsonObject.d.results[0];
switch($scope.current_user.Role){
case 'USR':
$scope.projectClose = 'true';
break;
case 'PMG':
$scope.projectClose = 'false';
break;
default:
$scope.projectClose = 'true';
break;
} // end switch
$scope.$apply();
} // end if
})
.fail(function(err){
$scope.prefPane = true;
console.info(JSON.stringify(err));
});
在第一个块上设置'$ scope.loggedInUser'并在第二个(现有用户)块上设置'$ scope.currentUser'。那是对的吗? –
是的。 loggedInUser包含SharePoint关于用户的信息。 current_user包含我在itiUsers表中的用户所维护的信息。每次使用都将记录用户信息,但只有现有用户才会拥有current_user信息。但我必须将首选项窗格中未编辑的信息分配给current_user,以使它们的Prefs窗体可以工作。这就是在“$ scope.current_user.DisplayName = $ scope.loggedInUser.Title;”分解的地方线。我应该推它,而不是分配它吗? – jgravois