过滤AngularJS中的JSON数据
有人能帮我解决我面临的以下问题吗?我的主要目的是根据名称和创建字段过滤数据,我想得到这个月名为“正在进行”和“已创建”字段的计数,是否有任何简单的方法可以轻松地使用Angular JS,我现在也只得到“正在进行”字段,但将来我还需要使用其他值进行过滤 普朗克演示 JS过滤AngularJS中的JSON数据,angularjs,json,angularjs-filter,Angularjs,Json,Angularjs Filter,有人能帮我解决我面临的以下问题吗?我的主要目的是根据名称和创建字段过滤数据,我想得到这个月名为“正在进行”和“已创建”字段的计数,是否有任何简单的方法可以轻松地使用Angular JS,我现在也只得到“正在进行”字段,但将来我还需要使用其他值进行过滤 普朗克演示 JS if(inputs.fields.status.name==“进行中”) 如果 (inputs.fields.status.name==$scope.selectedItem) $scope.selectedItem可能来自下拉
if(inputs.fields.status.name==“进行中”)
如果
(inputs.fields.status.name==$scope.selectedItem)
$scope.selectedItem可能来自下拉列表或其他内容。我希望我正确理解了你的问题。
$scope.selectedCount=$filter('filter')(response.data.issues,函数(输入){
如果(inputs.fields.status.name==‘进行中’
&&已创建==)
返回输入;
});
这就像矩().format('MM')==矩(已创建)。format('MM')为什么不尝试使用lodash来做这种逻辑?当然,让我试试这种方法。这对您有帮助吗?
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];
}
if (inputs.fields.status.name == 'IN PROGRESS')
could be if
(inputs.fields.status.name == $scope.selectedItem)
$scope.selectedItem could come from a dropdown or something. I hope I understood your question correctly.
$scope.selectedCount = $filter('filter')(response.data.issues, function(inputs) {
if (inputs.fields.status.name == 'IN PROGRESS'
&& created == <you need momentJs or some date compare
function to compare month>)
return inputs;
});