我正在努力解决我的问题...
首先,我通过ajax调用填充名为sourceArray的数组:
var form = $('<form method="POST" action="'+urlString+'">');
我的sourceArray返回一个非唯一数组,其中每个项目的registrationDate和source都有2个对象:
$.ajax({
url: '/api/WebService/getRegistrants?url=' + url + '&start=' + start + '&end=' + end + '&token=' + projectsArray[$("#dropdown").val()].apiToken,
type: 'GET',
async: false,
success: function (data) {
var source = [];
$.each(data.items, function (index, value) {
$.ajax({
url: '/api/WebService/getRegistrant?token=' + projectsArray[$("#dropdown").val()].apiToken + '®istrantId=' + value.registrantId,
type: "GET",
async: false,
success: function (data2) {
sourceArray.push({ registrationDate: data2.registrationDate.split("T")[0], source: data2.sourceType.sourceType });
}
});
});
}
});
现在我从ajax调用中获得了所需的一切,我执行了一个循环,但没有处理数据,而是在日期范围之间进行了循环:
{registrationDate: "2018-07-04", source: “New”},
{registrationDate: "2018-07-04", source: “New”},
{registrationDate: "2018-07-04", source: “Old”},
{registrationDate: "2018-07-03", source: “New”},
{registrationDate: "2018-07-03", source: “Old”},
{registrationDate: "2018-07-03", source: “Old”}
现在我要做的是获取源代码“ New”的总数,其中registrationDate = console.log([年,月,日] .join('-')),如果日期不相等,则返回0。
我真的希望这有意义。我的问题是如何过滤数组以获取“新”源的总数?
答案 0 :(得分:0)
想通了:
var find = $.grep(names, function(v) {
return v.registrationDate === [year, month, day].join('-') && v.source === "New";
});
console.log(find.length);