下面的函數返回此JSON對象:如何使用推一個循環內
[{"number":2,"des":"Ceintures De Sécurités Passagères","la_date":1506960648000},{"number":7,"des":"Ceintures De Sécurité Conducteur","la_date":1509542654000},{"number":1,"des":"Ceintures De Sécurités Passagères","la_date":1512134781000}]
功能:
$scope.loadDataFromToMonth= function (from,to,year) {
var url = servername+'admin/dashboard/getIncidentDepartByMonthFromTo/'+from+'/'+to+'/'+year;
alert(url);
function onSuccess(response) {
console.log("+++++getIncidentDepartByMonthFromTo SUCCESS++++++");
if (response.data.success != false) {
$scope.payloadgetIncidentDepartByMonthFromTo = response.data.data;
var getIncidentDepartByMonthFromTo= $scope.payloadgetIncidentDepartByMonthFromTo;
console.log(JSON.stringify(getIncidentDepartByMonthFromTo));
$scope.labels = [];
// charCtrl.toto = [];
// $scope.data = {};
//$scope.qsd.push('ff');
getIncidentDepartByMonthFromTo.forEach(function(data) {
// charCtrl.toto.push($filter('monthName')(monthNumber));
var monthNumber=$filter('date')(data.la_date, "MM");
//$scope.labelsf.push($filter('monthName')(monthNumber));
var mun=data.number;
//$scope.dataf.push(data.number);
$scope.data = {
labels: [monthNumber],
datasets: [
{
label: 'My First dataset',
fillColor: 'rgba(220,220,220,0.2)',
strokeColor: 'rgba(220,220,220,1)',
pointColor: 'rgba(220,220,220,1)',
pointStrokeColor: '#fff',
pointHighlightFill: '#fff',
pointHighlightStroke: 'rgba(220,220,220,1)',
data: [data.number]
}
]
};
});
}
else {
alert("failure");
}
};
function onError(response) {
console.log("-------getIncidentDepartByMonthFromTo FAILED-------");
//$scope.stopSpin('spinner-0');
console.log(response.data);
console.log("Inside getIncidentDepartByMonthFromTo error condition...");
};
//----MAKE AJAX REQUEST CALL to GET DATA----
ajaxServicess.getData(url,username,password, 'GET', '').then(onSuccess, onError);
};
我的問題是,在巴焦數據apprears,剛剛過去的出現json對象是:
{"number":1,"des":"Ceintures De Sécurités Passagères","la_date":1512134781000}
所以你只需要一個for循環邏輯來推送唯一的數據? –
循環工作良好..但我不知道我如何使用推內$ scope.data:{} –
當我這樣做$ scope.data:{labels.push(monthNumber)}它給出了一個錯誤 –