2013-08-31 62 views
0
Edited: Now this example fully works with external json service to see it in live 

我可以看到的console.log接收陣列而params,但我不能回顯數組的觀點...接收陣列

,網上JSON服務返回{"key": "value"}

如何使此{{some_item.key}}正常工作?謝謝!!

<!DOCTYPE html> 
<html ng-app="Simple"> 
<body> 
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js"></script> 
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular-resource.min.js"></script> 
<div ng-controller="SimpleController">  
    {{some_item.key}} 
</div> 
<script> 
angular.module('Simple', ['ngResource']); 
function SimpleController($scope, $resource) { 
    $scope.simple = $resource('http://echo.jsontest.com/key/value', 
     {callback:'JSON_CALLBACK'}, 
     {get:{method:'JSONP'}} 
    ); 
    $scope.some_item = $scope.simple.get(); 
    console.log($scope.some_item.key); 
} 
</script> 
</body> 
</html> 
+1

嘗試'$ scope.some_item [0]'。數組值通過索引訪問。 –

+0

感謝您的提示! – Gediminas

回答

2

你需要把插值後的控制器的範圍內這樣的

<div ng-controller="SimpleController">  
    {{some_item.key}} 
</div> 
+0

謝謝!我不能相信這是一個div放置錯誤! :) – Gediminas