使用AngularJS进入对象

时间:2017-08-17 09:35:33

标签: angularjs json

我的JSON文件有问题。我有一个旧的工作正常。

现在我得到一个新的,我没有找到进入第一个" main_themes" -Object的方法。

这是我的实际模块:

     angular.module('destinationsApp', [])
  .controller('destinationsCtrl', function($scope, $http){
    $http.get('https://raw.githubusercontent.com/MAHUKI-Webdesign/suntrips.github.io/master/data.json').then(function(itemsResponse) {
      $scope.items = itemsResponse.data;
    });
});

其实我用这样的东西做到了:

<li ng-repeat="item in items"><a href="#">{{item.name}}</a></li>

我该怎么做?

这是我的Plunkr的工作版本:

https://embed.plnkr.co/U4WHAFQRZ2JsUOJVlAu7/

这是我的Plunkr与无效版本:

https://embed.plnkr.co/b3OtRKgzp1OQ0h1L3jDA/

6 个答案:

答案 0 :(得分:1)

var url = "http://raw.githubusercontent.com/MAHUKI-Webdesign/suntrips.github.io/master/data.json";
$http({
    method: 'JSONP',
    url: url
}).
success(function(status) {
     $scope.items = itemsResponse.data;
                // handle valid reponse
}).
error(function(status) {
    //your code when fails
});

您正在获取'Access-Control-Allow-Origin' header is present on the requested resource. Origin来解决此更改其余的api以访问localhost。另请参阅this ..使用JSONP

答案 1 :(得分:0)

因为响应是一个对象,所以只需访问import io import picamera import cv2 import numpy from cbcnn import fire #Create a memory stream so photos doesn't need to be saved in a file stream = io.BytesIO() #Get the picture (low resolution, so it should be quite fast) #Here you can also specify other parameters (e.g.:rotate the image) with picamera.PiCamera() as camera: camera.resolution = (320, 240) camera.vflip = True camera.capture(stream, format='jpeg') #Convert the picture into a numpy array buff = numpy.fromstring(stream.getvalue(), dtype=numpy.uint8) #Now creates an OpenCV image image = cv2.imdecode(buff, 1) #Load a cascade file for detecting faces face_cascade = cv2.CascadeClassifier('/home/pi/cbot/faces.xml /haarcascade_frontalface_default.xml') #Convert to grayscale gray = cv2.cvtColor(image,cv2.COLOR_BGR2GRAY) #Look for faces in the image using the loaded cascade file faces = face_cascade.detectMultiScale(gray, 1.1, 5) print "Found "+str(len(faces))+" face(s)" if len(faces) > 0: ("fire") #Draw a rectangle around every found face for (x,y,w,h) in faces: cv2.rectangle(image,(x,y),(x+w,y+h),(255,0,0),2) #Save the result image cv2.imwrite('result.jpg',image) 属性。

main_themes

答案 2 :(得分:0)

访问 var aData = response.d; var arr = []; for (i = 0; i < aData.length; i++) { arr.push([aData[i].FileDate2.replace("/Date(", "").replace(")/", ""), aData[i].AutoReleasedPct]); }

main_themes

答案 3 :(得分:0)

试试这个

<!DOCTYPE html>
<html ng-app="app">

<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
<script >
	var app = angular.module('app', []);
	app.controller('myCtrl',function($scope, $http){
		$http.get('https://raw.githubusercontent.com/MAHUKI-Webdesign/suntrips.github.io/master/data.json').then(function(itemsResponse) {
			$scope.items = itemsResponse.data;
		});
	});
</script>
</head>
<body>
<div ng-controller='myCtrl'>
	<li ng-repeat="item in items"><a href="#">{{item.name}}</a></li>
</div>
</body>

</html>

答案 4 :(得分:0)

这是我的Plunkr与工作版本:

https://embed.plnkr.co/U4WHAFQRZ2JsUOJVlAu7/

这是我的Plunkr,其中无效版本:

https://embed.plnkr.co/b3OtRKgzp1OQ0h1L3jDA/

答案 5 :(得分:0)

它不适用于Plunker;

我得到的错误:

Mixed Content: The page at 'https://plnkr.co/edit/b3OtRKgzp1OQ0h1L3jDA?p=preview' was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint 'http://www2.suntrips.de/import/main_sub_themes-main.json'. This request has been blocked; the content must be served over HTTPS

使用Plunker时,请使用HTTPS协议向服务器发出请求。