What I need help with is how to control/present the key values. The JSON file looks something like this:
{"offers":
[{"id":5,
"title":"beef",
"checkouts":
{
"2014-05-26":610,
"2014-03-20":792,
"2014-05-21":809,
... and so on
}
}]
}
So I get the data from a url with factory function using $resource so the data becomes a javascript Object. If I want to present the other data like titles, id etc. I just build a controller like this:
myApp.controller('meatTitlesCtrl', ['$scope', 'Offers', function ($scope, Offers) {
$scope.offers = Offers.get({});
$scope.orderProp = 'title';
}
]);
Then I invoke it in index.html something like this:
<div ng-controller="meatTitlesCtrl">
<ul>
<li ng-repeat="offer in offers.offers | orderBy: 'title'">
{{offer.title}}
<ul>
<li ng-repeat="(key, value) in offer.checkouts">
<strong>{{key}}</strong> : {{value}}
</li>
</ul>
</li>
</ul>
</div>
So what I get now if I test it values like this in a list:
beef
2014-02-26 : 967
2014-02-28 : 101
2014-03-01 : 105
So how can I control the keyvalues and values like separated objects in a good angular way?
I was thinking of : the angular.foreach in some kind of wway, just kind find out how to implement it. Any suggestions?
Guru- "Are you looking for an array of keys and array of values as separate objects from the above json?"
Can“t of some reason not answer Gurs comment. But yes! Im looking for one array for keys and one array for values as separate objects from the above json format.