我正在尝试显示我的Json元素的值,
“Baru20151”, “Lama20151”, “Baru20152”, “Lama20152”, 但我不知道怎么做。
元素从2个数组中检索, 在“Baru20151”元素中,“20151”是从我的Json文件中的“isimasa”数组中检索的。
HTML:
<div ng-app="myApp" ng-controller="RegistrationCtrl">
<h4 style="text-align:center">REGISTRASI MAHASISWA PENDAS</h4>
<table class="table table-striped table-bordered table-hover">
<tr>
<td ng-repeat-start="Isimasa in myDataIsimasa" align="center">Baru</td>
<td align="center">Lama</td>
</tr>
<tr ng-repeat="Pendas in DataPendas" >
<td ng-repeat-start="Isimasa in DataIsimasa" align="center">{{Pendas.Baru{{Isimasa.masa}}}}</td>
<td align="center">{{Pendas.Lama{{Isimasa.masa}}}}</td>
</tr>
</table>
</div>
控制器:
<script>
var app = angular.module('myApp', []);
app.controller('RegistrationCtrl', function($scope, $http) {
$http.get("json.json").then(function (response) {
$scope.DataPendas = response.data.pendas;
$scope.DataIsimasa = response.data.isimasa;
$scope.Data = response.data;
});
});
</script>
杰森:
{"name":"ACEH",
"isimasa":[{"masa":"20151"},{"masa":"20152"}],
"column":9,
"pendas":[
{"kode":"121","prodiname":"PGPAUD", "Baru20151":22,"Lama20151":0,
"Baru20152":22,"Lama20152":20}
]}
答案 0 :(得分:0)
试试这个.. 控制器:
<script>
var app = angular.module('myApp', []);
app.controller('RegistrationCtrl', function($scope, $http) {
$http.get("json.json").then(function (response) {
$scope.DataPendas = response.data.pendas;
//console.log($scope.DataPendas);
$scope.DataIsimasa = response.data.isimasa;
var isimasa = $scope.DataIsimasa;
console.log(isimasa);
$scope.Data = response.data;
$scope.constructJson = constructJson;
function constructJson(theKey, jsonKey, jsonObj){
console.log(theKey, jsonKey);
var newKey = theKey + jsonKey;
var newValue = jsonObj[newKey];
console.log(newValue);
return newValue;
}
});
});
</script>
HTML:
<div ng-app="myApp" ng-controller="RegistrationCtrl">
REGISTRASI MAHASISWA PENDAS
<table class="table table-striped table-bordered table-hover">
<tr ng-repeat-start="Isimasa in DataIsimasa">
<td>{{Isimasa.masa}}
<div ng-repeat="Pendas in DataPendas">
Baru{{Isimasa.masa}} : {{ constructJson("Baru",Isimasa.masa, Pendas ) }}<br/>
Lama{{Isimasa.masa}} : {{ constructJson("Lama",Isimasa.masa, Pendas ) }}
</div>
</td>
</tr>
<tr ng-repeat-end>
</tr>
</table>