2017-10-16 85 views
0

我如何從Hal表示中獲取任何對象ID?使用角度從HAL表示獲取ID

準確地說,我想從所有用戶列表中的特定用戶獲取此信息。有例子:

{ 
    "_embedded" : { 
    "users" : [ { 
     "login" : "user1", 
     "firstName" : "Bolek", 
     "lastName" : "Kowal", 
     "email" : null, 
     "password" : null, 
     "gender" : null, 
     "birthDate" : null, 
     "_links" : { 
     "self" : { 
      "href" : "http://localhost:8080/games-organizer/api/users/1" 
     }, 
     "user" : { 
      "href" : "http://localhost:8080/games-organizer/api/users/1" 
     }, 
     "roles" : { 
      "href" : "http://localhost:8080/games-organizer/api/users/1/roles" 
     } 
     } 
    }, { 
     "login" : "user2", 
     "firstName" : "Lolek", 
     "lastName" : "Kowalski", 
     "email" : null, 
     "password" : null, 
     "gender" : null, 
     "birthDate" : null, 
     "_links" : { 
     "self" : { 
      "href" : "http://localhost:8080/games-organizer/api/users/2" 
     }, 
     "user" : { 
      "href" : "http://localhost:8080/games-organizer/api/users/2" 
     }, 
     "roles" : { 
      "href" : "http://localhost:8080/games-organizer/api/users/2/roles" 
     } 
     } 
    } 

最終如何刪除特定用戶使用休息彈簧API和角度/彈簧?我不知道如何在沒有任何用戶(對象)的id的情況下做到這一點。

更新:

我想用這個ID,在調用一些像這樣的方法:

$scope.$on('deleteUser', function (event, id) { 
     userService.delete({id: id}).$promise.then(
      function() { 
       // Broadcast the event to refresh the grid. 
       $rootScope.$broadcast('refreshUserGrid'); 
       // Broadcast the event to display a delete message. 
       $rootScope.$broadcast('userDeleted'); 
       $scope.clearForm(); 
      }, 
      function() { 
       // Broadcast the event for a server error. 
       $rootScope.$broadcast('error'); 
      }); 

    }); 

我想在springRestAPI從數據庫中刪除了一些記錄。

+0

ID? – vertika

+0

這意味着我不知道如何從該表示中的任何用戶獲取id。我應該以任何方式使用鏈接嗎? – smok010

+0

如果你知道你要刪除哪個用戶,那麼最新的問題是什麼? – vertika

回答

0

假設你要刪除用戶2的細節,那麼你可以這樣做:

從任何用戶的手段沒有
For (var i=0;i<allUser.users.length;i++){ 
    if(allUser.users[i].login=="user2"){ 
     allUser.users.splice(i-1,i); 
    } 
} 
+0

這不完全是我的意思。我更新了我的答案。我想要id在我的服務方法中使用它來從數據庫中刪除記錄。不僅從這個名單。 – smok010