i'm using angularjs
, json
file hold data. , data holds array objects , values.
here's json:
{ "directorylist": [ { "_id": 2, "navlvl": 1, "codename": "bod", "directoryname": "board of directors", "contacts": [ { "bodname": "fvc", "position": "ceo", "localno": "101", "mobile": ["09178985698", "09178985698"] }, { "bodname": "mic", "position": "president", "localno": "108", "mobile": ["09178710088", "09178889088"] }, { "bodname": "sic", "position": "svc-optrns", "localno": "105", "mobile": ["09178923689", "09328922955"] } ] } ] }
and in controller:
$http.get('./json/directory.json') .success(function(data){ var result = $filter('filter')(data.directorylist, {_id:$stateparams.id})[0]; $scope.listviews = []; angular.foreach(result, function(value, key) { $scope.listviews.push(value); }); }) .error(function(err){ $log.error(err); })
and in views:
<div class="table-responsive" ng-if="listviews[0] == 2"> <table class="table table-striped table-hover table-condensed table-bordered"> <tr> <thead> <th>bod name</th> <th>position</th> <th>local no.</th> <th>mobile</th> </thead> </tr> <tr> <tbody ng-repeat="list in listviews[4]"> <td ng-repeat="(key, value) in list">{{ value }}</td> </tbody> </tr> </table> </div>
this gives me:
bod name | position |local no. | mobile ---------+----------+----------+------------------------------- fvc | ceo | 101 | ["09178985698","09178985698"] ---------+----------+----------+------------------------------- mic | president| 108 | ["09178710088","09178889088"] ---------+----------+----------+------------------------------- sic |svc-optrns| 105 | ["09178923689","09328922955"]
i have no idea how display correctly when try change value
value[0]
can first array ruins data holds objects. there way getting data objects values? can't figure out should execute logic. way better in controller or in view?
i'm pretty sure there lot of different ways on doing this. following 1 should work.
<tbody ng-repeat="list in listviews[4]"> <td ng-repeat="(key, value) in list"> <div ng-if="key=='mobile'" ng-repeat="phone in value">{{phone}} </div> <div ng-if="key!='mobile'">{{value}}</div> </td> </tbody>