誰かが私に直面している問題があります。私の主な目的は、名前と作成されたフィールドに基づいてデータをフィルタリングすることです。名前がIN PROGRESSと今月のフィールドを作成しました。簡単な方法でAngular JSに簡単にアプローチすることができます。また、今でもIN PROGRESSフィールドだけを取得していますが、将来は他の値でもフィルタリングする必要があります。AngularJSでJSONデータをフィルタリングする
Plunkerデモ
JS
var app = angular.module('myApp', []);
app.controller("Controller", ["$scope", "$http", "$filter", "$window",
function ($scope, $http, $filter, $window) {
$scope.findTheValue = function() {
$http({
method: 'GET',
url: 'issues.json'
}).then(function (response) {
$scope.selectedCount = $filter('filter')(response.data.issues, function (inputs) {
if (inputs.fields.status.name == 'IN PROGRESS')
return inputs;
});
console.log($scope.selectedCount.length);
$scope.dayCount = 0;
$scope.monthEventCount = 0;
// Finding the The value of Day, Week and Month With Respect to Today's Date
var todayAsBase = new Date();
var todayAsBaseday = todayAsBase.getDay();
var todayAsBaseWeek = getWeekNumber(todayAsBase)[0];
var todayAsBaseMonth = todayAsBase.getMonth();
console.log(todayAsBaseday, todayAsBaseWeek, todayAsBaseMonth);
$scope.dayEventCount = 0;
$scope.weekEventCount = 0;
$scope.monthEventCount = 0;
angular.forEach(response.data.issues, function (issue) {
issueDate = new Date(issue.fields.created);
day = issueDate.getDay();
week = getWeekNumber(issueDate)[0];
month = issueDate.getMonth();
if (week == todayAsBaseWeek)
$scope.weekEventCount = $scope.weekEventCount + 1;
if (month == todayAsBaseMonth)
$scope.monthEventCount = $scope.monthEventCount + 1;
if (day == todayAsBaseday && week == todayAsBaseWeek && month == todayAsBaseMonth)
$scope.dayEventCount = $scope.dayEventCount + 1;
});
console.log($scope.dayEventCount, $scope.weekEventCount, $scope.monthEventCount);
})
}
}
]);
function getWeekNumber(d) {
// Copy date so don't modify original
d = new Date(Date.UTC(d.getFullYear(), d.getMonth(), d.getDate()));
// Set to nearest Thursday: current date + 4 - current day number
// Make Sunday's day number 7
d.setUTCDate(d.getUTCDate() + 4 - (d.getUTCDay() || 7));
// Get first day of year
var yearStart = new Date(Date.UTC(d.getUTCFullYear(), 0, 1));
// Calculate full weeks to nearest Thursday
var weekNo = Math.ceil((((d - yearStart)/86400000) + 1)/7);
// Return array of year and week number
return [weekNo];
}
なぜこの種のロジックをするためにロダッシュを使用しようとしないのですか? –