중첩 된 JSON 값에 액세스하는 데 문제가 있습니다. 나는 다른 값을 얻습니다. 그것은 내가 문제가있는 중첩 된 값입니다. 이 예제를 따르려고했지만 작동하지 못했습니다. AngularJS로 중첩 된 JSON 액세스
<div ng-app="myApp" ng-controller="customersCtrl">
<ul>
<li ng-repeat="x in myData">
{{ x.Body + ', ' + x.title + ', ' + x.test_l.filename + ', ' + x.test_h.filename }}
</li>
</ul>
<!--problem here -->
<ul ng-repeat="x in myData" ng-show="isVisible(x.title)">
<li ng-repeat="y in x.image">{{y.filename}}</li>
</ul>
내 문제는 마지막 부분입니다. 이미지의 모든 파일 이름을 얻으려고합니다.
var app = angular.module('myApp', []);
app.controller('customersCtrl', function($scope, $http) {
$http.get("http://localhost:8012/Adrupal/apistuff/test.json").then(function(response) {
$scope.myData = response.data;
});
});
JSON
[
{
"Body": "This is the first test",
"nid": "1",
"test_h": {
"fid": "33",
"uid": "1",
"filename": "h_pic.png",
"uri": "public://h_pic.png",
"filemime": "image/png",
"filesize": "387",
"status": "1",
"timestamp": "1465557583",
"rdf_mapping": [],
"alt": "",
"title": "",
"width": "88",
"height": "105"
},
"test_l": {
"fid": "34",
"uid": "1",
"filename": "l_pic.png",
"uri": "public://l_pic.png",
"filemime": "image/png",
"filesize": "315",
"status": "1",
"timestamp": "1465557850",
"rdf_mapping": [],
"alt": "",
"title": "",
"width": "67",
"height": "93"
},
"image": [
{
"fid": "28",
"uid": "1",
"filename": "image1.png",
"uri": "public://image1_0.png",
"filemime": "image/png",
"filesize": "39965",
"status": "1",
"timestamp": "1465556955",
"rdf_mapping": [],
"alt": "",
"title": "",
"width": "226",
"height": "208"
},
{
"fid": "35",
"uid": "1",
"filename": "image2.png",
"uri": "public://image2.png",
"filemime": "image/png",
"filesize": "64329",
"status": "1",
"timestamp": "1465563195",
"rdf_mapping": [],
"alt": "",
"title": "",
"width": "321",
"height": "201"
}
],
"title": "Test 1",
"Check High": "1",
"Check Low": "1"
}
]
미리 감사드립니다
에 문제가 ng-show="isVisible(x.title)"
있습니다. 사용하는 ng-show="x.title"
대신 ng-show="isVisible(x.title)"
.
바이올린 데모 : https://jsfiddle.net/U3pVM/25488/
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다