ng-repeat를 사용하여 angularjs에서 json 데이터를 인쇄하는 방법. ng-repeat에서는 예를 들어 "data": [{ "y": "23", "x": "12"}] 만 인쇄하고 싶습니다 . json 데이터를 참조하십시오. 그러나 그것은 html로 아무것도 인쇄하지 않습니다.
데모 : http://plnkr.co/edit/zy1C2z39dXuuHDx8eqxK?p=preview
JSON 데이터
{"series": [{"meter": "instance", "data": [{"y": 1.0, "x": "2015-07-21T14:21:33"}, {"y": 1.0, "x": "2015-07-22T14:21:34"}, {"y": 1.0, "x": "2015-07-23T14:21:34"}, {"y": 1.0, "x": "2015-07-24T14:23:39"}, {"y": 1.0, "x": "2015-07-25T14:23:39"}, {"y": 1.0, "x": "2015-07-26T02:43:39"}, {"y": 1.0, "x": "2015-07-27T14:24:33"}], "name": "demo", "unit": "instance"}], "settings": {}}
Angularjs
app.controller('ceilometerCtrl', function($scope, $http) {
$http.get("http://192.168.206.133:8080/admin/metering")
.success(function(response) {
$scope.metrics=response.series[0].data;
});
});
HTML
<div ng-controller="ceilometerCtrl">
<div ng-repeat="metric in metrics">
Metric: {{metric.x}}
</div>
</div>
결과 아무것도 인쇄되지 않습니다.
Metric:
Metric:
Metric:
Metric:
Metric:
Metric:
Metric:
코드를 두 번 변경해야합니다.
series
배열과 마찬가지로 업데이트
$scope.metrics=response.series.data;
...에
$scope.metrics=response.series[0].data;
x
및 y
메트릭의 속성이다. 에서 업데이트
Metric: {{metric.data.x}}
...에
Metric: {{metric.x}}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다