2017-09-05 141 views
2

所以我有我的控制器,它有一個名字,豆類列表和操作的列表下列對象:提取信息

{ 
    "name": "Charge", 
    "beans": [ 

    ], 
    "operations": [ 
    { 
     "name": "getSize", 
     "returnType": "java.lang.Integer", 
     "description": "empty description", 
     "parameters": [ 

     ] 
    }, 
    { 
     "name": "truncate", 
     "returnType": "java.lang.Void", 
     "description": "empty description", 
     "parameters": [ 

     ] 
    }, 
    { 
     "name": "count", 
     "returnType": "java.lang.Integer", 
     "description": "empty description", 
     "parameters": [ 
     { 
      "name": "javaCode", 
      "type": "java.lang.String", 
      "value": null 
     } 
     ] 
    }, 
    { 
     "name": "update", 
     "returnType": "java.lang.Integer", 
     "description": "empty description", 
     "parameters": [ 
     { 
      "name": "javaSelectCode", 
      "type": "java.lang.String", 
      "value": null 
     }, 
     { 
      "name": "javaUpdateCode", 
      "type": "java.lang.String", 
      "value": null 
     } 
     ] 
    }, 
    { 
     "name": "delete", 
     "returnType": "java.lang.Integer", 
     "description": "empty description", 
     "parameters": [ 
     { 
      "name": "javaCode", 
      "type": "java.lang.String", 
      "value": null 
     } 
     ] 
    }, 
    { 
     "name": "dump", 
     "returnType": "java.lang.Void", 
     "description": "empty description", 
     "parameters": [ 
     { 
      "name": "javaSelectCode", 
      "type": "java.lang.String", 
      "value": null 
     }, 
     { 
      "name": "destinationPath", 
      "type": "java.lang.String", 
      "value": null 
     } 
     ] 
    }, 
    { 
     "name": "select", 
     "returnType": "java.lang.String", 
     "description": "empty description", 
     "parameters": [ 
     { 
      "name": "javaCode", 
      "type": "java.lang.String", 
      "value": null 
     } 
     ] 
    } 
    ], 
    "$$hashKey": "object:620" 
} 

基本上,我想從這個對象顯示所有操作在下拉菜單中。

所以我在想有什麼樣的:

<div ng-repeat="operation in object.operations"> 
    {{operation.name}} 
</div> 

除了上面的代碼不會顯示任何屏幕上,在控制檯中沒有錯誤,沒有什麼。

任何幫助將不勝感激!

編輯:

的Javascript服務:

app.controller('selectAll', ['$http', '$scope' , '$rootScope', function ($http, $scope, $rootScope) { 

    $scope.response; 
    $scope.operations; 

    $rootScope.$on("invokeSelectAll", function(){ 
     $scope.invokeSelectAll(); 
    }); 

    $scope.invokeSelectAll = function(){ 
     $scope.response = $http.post('/invoke/selectAll/', $rootScope.dataObj); 
     $scope.object = JSON.stringify($rootScope.object); 
     console.log(" object operation from selectAll " + $scope.object); 
     $scope.response.then(function(data) { 
      $scope.responses = data.data ? data.data : "Select Operation not supported on this bean"; 
     }); 
    } 
}]); 

,開發者控制檯的屏幕截圖: https://imgur.com/a/8WAAL

+1

嘗試使用* ngFor –

+2

這對角或AngularJS?我有一種感覺,你已經使用了錯誤的標籤 –

+0

我使用的是角度爲1.6的 –

回答

1

使用JSON.stringify()創建從JavaScript對象的JSON字符串。使用JSON.parse()將JSON字符串解析爲JavaScript對象。

在你的情況下,你需要使用JSON.parse(),因爲你從服務器得到一個JSON字符串並且想把它解析成一個JavaScript對象。

$scope.object = JSON.parse($rootScope.object); 
1

你透過JSON.stringify它是用來javascript對象更改爲字符串,並將其存儲爲唯一的字符串。

您應該使用JSON.parse()解析數據,並將數據變爲JavaScript對象。你可以在ng-repeat中輕鬆使用它。

試試吧,它會正常工作