[英]Need help to show two arrays in one table
There are 2 option My database is constructed like this 有2个选项我的数据库是这样构造的
{
"_id" : ObjectId("58ecbb3be949603f122dfcc4"),
"work_id" : 651853,
"date" : ISODate("2017-04-10T00:00:00.000Z"),
"updated_at" : ISODate("2017-04-11T11:17:42.067Z"),
"name" : "John Doe",
"wage_type" : [
{
"_id" : ObjectId("58ecbb567f7ed00c2ca041b6"),
"type_ident" : "157",
"start_string" : "020000",
"start_time" : "02:00:00",
"total" : "08:00:00",
"end_time" : "09:59:59",
"end_string" : "095959",
"group" : "Wage Type<br/>",
"end_date" : "2017-04-10",
"type" : "Morning Hours",
"start_date" : "2017-04-10",
"time_sheet_ident" : "248288"
}
],
"campaign" : [
{
"_id" : ObjectId("58ecbb567f7ed00c2ca041b5"),
"type_ident" : "165",
"start_string" : "020000",
"start_time" : "02:00:00",
"total" : "08:00:00",
"end_time" : "09:59:59",
"end_string" : "095959",
"group" : "Campaign<br/>",
"end_date" : "2017-04-10",
"type" : "Waitter",
"start_date" : "2017-04-10",
"time_sheet_ident" : "248288"
}
],
"__v" : 0,
"created_at" : ISODate("2017-04-11T11:17:13.182Z")
}
But I find 2 difficulties First when an worker has this structure 但是我发现2个困难首先是工人有这种结构
Based on user wage 根据用户工资
John Doe | Morning Hours | 4.00-12.00
Based on user campaign 根据用户活动
John Doe | Waiter | 4.00-8.00
John Doe | Bartender | 8.00-12.00
And this is the other option 这是另一种选择
Jim Dow | Morning Hours | 9.00-16.00
JIm Dow | Night Hours | 16-18
Based on campaign 根据广告系列
Jim Dow | Waitter | 9.00-18.00
What i could do till now is when the have the same start time and end time so i pass the campaign in which he worked on 到目前为止,我能做的是,当开始时间和结束时间相同时,我通过了他参与的活动
The difficult part which i cant find out is when they are 2 john doe on database on different campaigns or 2 jim dow on 2 different timesheets 我无法找到的困难部分是,当它们是数据库中不同活动的2个约翰·道伊或2个不同时间表的2个吉姆·道当时
If u can help me thanks in advance 如果可以的话我可以谢谢你
Solved it on my won 解决了我的胜利
for (let i = 0; i < timesheets.length; i++) { for(让i = 0; i <timesheets.length; i ++){
if (timesheets[i].wage_type !== 'none' && timesheets[i].wage_type || timesheets[i].campaign !== 'none' && timesheets[i].campaign ) {
for (let j = 0; j < timesheets[i].wage_type.length; j++) {
for (let k = 0; k < timesheets[i].campaign.length; k++){
if(timesheets[i].wage_type[j].start_time == timesheets[i].campaign[k].start_time && timesheets[i].wage_type[j].end_time == timesheets[i].campaign[k].end_time && timesheets[i].wage_type[j].time_sheet_ident == timesheets[i].campaign[k].time_sheet_ident ) {
const temp = {};
temp.ccms_id = timesheets[i].ccms_id;
temp.date = timesheets[i].date;
temp.name = timesheets[i].name;
temp.campaign = timesheets[i].campaign[k].type;
temp.type = timesheets[i].wage_type[j].type;
temp.start_time = timesheets[i].wage_type[j].start_time;
temp.end_time = timesheets[i].wage_type[j].end_time;
temp.total = timesheets[i].wage_type[j].total;
wages.push(temp);
}
else if (timesheets[i].wage_type[j].start_time <= timesheets[i].campaign[k].start_time && timesheets[i].wage_type[j].end_time >= timesheets[i].campaign[k].end_time ){
const temp = {};
temp.ccms_id = timesheets[i].ccms_id;
temp.date = timesheets[i].date;
temp.name = timesheets[i].name;
temp.campaign = timesheets[i].campaign[k].type;
temp.type = timesheets[i].wage_type[j].type;
temp.start_time = timesheets[i].campaign[k].start_time;
temp.end_time = timesheets[i].campaign[k].end_time;
temp.total = timesheets[i].campaign[k].total;
wages.push(temp);
}
else if (timesheets[i].wage_type[j].start_time >= timesheets[i].campaign[k].start_time && timesheets[i].wage_type[j].end_time <= timesheets[i].campaign[k].end_time ){
const temp = {};
temp.ccms_id = timesheets[i].ccms_id;
temp.date = timesheets[i].date;
temp.name = timesheets[i].name;
temp.campaign = timesheets[i].campaign[k].type;
temp.type = timesheets[i].wage_type[j].type;
temp.start_time = timesheets[i].wage_type[j].start_time;
temp.end_time = timesheets[i].wage_type[j].end_time;
temp.total = timesheets[i].wage_type[j].total;
wages.push(temp);
}
}
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.