iterate JSON response in Angular project to create new $scope obj i can
use in the app
JSON:
[{
"SHFUserID": "400",
"Status": "2",
"Ticker": "DPAX",
"TickerID": "4512",
"TotalBought": "6300.000000",
"TotalSold": "4200.000000",
"TotalSharesNow": "23500.000000"
},
{
"SHFUserID": "400",
"Status": null,
"Ticker": "DPAX",
"TickerID": "4512",
"TotalBought": "70500.000000",
"TotalSold": "47000.000000",
"TotalSharesNow": "45000.000000"
},
{
"SHFUserID": "400",
"Status": null,
"Ticker": "ONP",
"TickerID": "10190",
"TotalBought": "1175.000000",
"TotalSold": "1645.000000",
"TotalSharesNow": "-470.000000"
}]
I am trying to iterate over the Json to create a new obj that only
contains unique TickerID BUT still populates the "Pending" or "Settled"
value if the record Status is a 1 or 2 respectively.
new desired object {"ticker": "Ticker", "tickerId": "TickerID", "Pending":
0 or 1, "Settled": 0 or 1}
expected result based on example data: {"ticker": "DPAX", "tickerId":
4512, "Pending":0, "Settled": 1},{"ticker": "ONP", "tickerId": 10190,
"Pending":0, "Settled": 0}
the javascript code is in a controller.js file in an angular project. No
matter what code i use to iterate over the existing JSON I get an empty
array returned. I've tried a for loop, for in loop and when I run a simple
ticker.length function on the existing JSON it returns 0??
controller.js:
function TickerListCtrl($scope, Ticker) {
var ticker = [];
ticker = Ticker.query();
$scope.tickers = ticker;
$scope.tickerMenu = ticker.length;
...
}
resource.js
angular.module('tickerServices', ['ngResource']).
factory('Ticker', function($resource){
return $resource('http:........../Rest/tickers.php', {}, {
query: {method:'GET', params:{UserID:400}, isArray:true}
});
});
html:
...
<div class="span3">
<!--Sidebar content-->
...
<ul class="tickerList">
<li ng-repeat="ticker in tickers | filter:query | orderBy:orderProp">
<a href="#/ticker/</p>
</li>
</ul>
{{tickerMenu}}
</div>
the browser outputs the "tickerList" as expected but the {{tickerMenu}}
returns 0. Not sure what I am missing.
No comments:
Post a Comment