我正在使用slicnav构建菜单导航系统。我有一个居民事故清单,并且正在按日期构建系统。我想要一年然后一个月然后一天展开的导航,然后按天列出事件。
以下是一些json数据:
{
"incidents" : [{
"securityincidentid" : 2928,
"incyear" : 2019,
"incyearmonth" : "2019-4",
"incyearmonthday" : "2019-4-15",
"monthname" : "April",
"incday" : 15,
"incidentdatetime" : "2019-04-15 17:15:00.000",
"resemployees" : "5:15PM "
}, {
"securityincidentid" : 2930,
"incyear" : 2019,
"incyearmonth" : "2019-4",
"incyearmonthday" : "2019-4-15",
"monthname" : "April",
"incday" : 15,
"incidentdatetime" : "2019-04-15 14:13:00.000",
"resemployees" : "2:13PM"
}, {
"securityincidentid" : 2933,
"incyear" : 2019,
"incyearmonth" : "2019-4",
"incyearmonthday" : "2019-4-15",
"monthname" : "April",
"incday" : 15,
"incidentdatetime" : "2019-04-15 14:00:00.000",
"resemployees" : "2:00PM "
}, {
"securityincidentid" : 2927,
"incyear" : 2019,
"incyearmonth" : "2019-4",
"incyearmonthday" : "2019-4-15",
"monthname" : "April",
"incday" : 15,
"incidentdatetime" : "2019-04-15 14:00:00.000",
"resemployees" : "2:00PM "
}, {
"securityincidentid" : 2929,
"incyear" : 2019,
"incyearmonth" : "2019-4",
"incyearmonthday" : "2019-4-15",
"monthname" : "April",
"incday" : 15,
"incidentdatetime" : "2019-04-15 13:55:00.000",
"resemployees" : "1:55PM"
}, {
"securityincidentid" : 2931,
"incyear" : 2019,
"incyearmonth" : "2019-4",
"incyearmonthday" : "2019-4-14",
"monthname" : "April",
"incday" : 14,
"incidentdatetime" : "2019-04-14 09:52:00.000",
"resemployees" : "9:52AM"
}]}
这是构建菜单的jQuery代码
var
incyear="",
incyearmonth="",
incyearmonthday="";
$.each(navdata.incidents,function(key,value){
if(incyear!==value.incyear){
$securityincidenul.append(
$('<li>').prop({id:value.incyear+"-fd"}).text(value.incyear).append(
$('<ul>').prop({id:value.incyear+"-fd-ul"}).append(
$('<li>').prop({id:value.incyearmonth+"-fd"}).text(value.monthname).append(
$('<ul>').prop({id:value.incyearmonth+"-fd-ul"}).append(
$('<li>').prop({id:value.incyearmonthday+"-fd"}).text(value.incday).append(
$('<ul>').prop({id:value.incyearmonthday+"-fd-ul"}).append(
$('<li>').prop({id:value.securityincidentid}).append(
$('<a>').prop({href:"#"}).click(function(){
createsecincidentform(value.securityincidentid)
}).text(value.resemployees)
)
)
)
)
)
)
)
)
}else if(incyearmonth!==value.incyearmonth){
$("#"+incyear+"-fd-ul").append(
$('<li>').prop({id:value.incyearmonth+"-fd"}).text(value.monthname).append(
$('<ul>').prop({id:value.incyearmonth+"-fd-ul"}).append(
$('<li>').prop({id:value.incyearmonthday+"-fd"}).text(value.incday).append(
$('<ul>').prop({id:value.incyearmonthday+"-fd-ul"}).append(
$('<li>').prop({id:value.securityincidentid}).append(
$('<a>').prop({href:"#"}).click(function(){
createsecincidentform(value.securityincidentid)
}).text(value.resemployees)
)
)
)
)
)
)
}else if(incyearmonthday!==value.incyearmonthday){
$("#"+value.incyearmonth+"-fd-ul").append(
$('<li>').prop({id:value.incyearmonthday+"-fd"}).text(value.incday).append(
$('<ul>').prop({id:value.incyearmonthday+"-fd-ul"}).append(
$('<li>').prop({id:value.securityincidentid}).append(
$('<a>').prop({href:"#"}).click(function(){
createsecincidentform(value.securityincidentid)
}).text(value.resemployees)
)
)
)
)
}else if(incyearmonthday===value.incyearmonthday){
$("#"+value.inceyearmonthday+"-fd-ul").append(
$('<li>').prop({id:value.securityincidentid}).append(
$('<a>').prop({href:"#"}).click(function(){
createsecincidentform(value.securityincidentid)
}).text(value.resemployees)
)
)
}
incyear=value.incyear;
incyearmonth=value.incyearmonth;
incyearmonthday=value.incyearmonthday;
})
如您所见,我在2019年4月15日有4条记录,然后在2019年4月14日有一条记录。它仅显示每天的第一条记录,而不显示随后的记录。有什么想法吗?