4
4
import java .text .SimpleDateFormat ;
5
5
import java .util .ArrayList ;
6
6
import java .util .Calendar ;
7
+ import java .util .Collections ;
7
8
import java .util .Comparator ;
8
9
import java .util .Date ;
9
10
import java .util .HashMap ;
@@ -111,21 +112,21 @@ public String createInitTree(){
111
112
}
112
113
Calendar todayCalendar = Calendar .getInstance ();//先调用getInstance得到一个Calendar的对象
113
114
todayCalendar .setTime (new Date ());//然后将Date(这里为现场时间new Date)的对象设置入Calendar调用setTime即可,随后Calendar就可以取出月份,年份,每月几号等信息了
114
- int currentYear = todayCalendar .get (Calendar .YEAR );
115
- int currentMonth = todayCalendar .get (Calendar .MONTH )+1 ;//Calendar的Month居然是从0开始的,详见API:一年中的第一个月是 JANUARY,它为 0;最后一个月取决于一年中的月份数。
116
- int currentDay = todayCalendar .get (Calendar .DAY_OF_MONTH );//而Calendar的DAY_OF_MONTH是从1开始的,详见API:get 和 set 的字段数字,指示一个月中的某天。它与 DATE 是同义词。一个月中第一天的值为 1。
115
+ // int currentYear = todayCalendar.get(Calendar.YEAR);
116
+ // int currentMonth = todayCalendar.get(Calendar.MONTH)+1;//Calendar的Month居然是从0开始的,详见API:一年中的第一个月是 JANUARY,它为 0;最后一个月取决于一年中的月份数。
117
+ // int currentDay = todayCalendar.get(Calendar.DAY_OF_MONTH);//而Calendar的DAY_OF_MONTH是从1开始的,详见API:get 和 set 的字段数字,指示一个月中的某天。它与 DATE 是同义词。一个月中第一天的值为 1。
117
118
for (Map .Entry <Integer , List <Integer >> year_month : year_months .entrySet ()){
118
119
int year = year_month .getKey ();
119
120
Element yearElement = root .addElement ("node" );
120
- if (unfoldCurrentMonth && currentYear == year ){
121
+ if (unfoldCurrentMonth && Collections . max ( year_months . keySet ()). equals ( year )){ //修改为最大年份的就展开
121
122
yearElement .addAttribute ("open" , "true" );
122
123
}else {
123
124
yearElement .addAttribute ("open" , "false" );
124
125
}
125
126
yearElement .addAttribute ("id" ,String .valueOf (year )).addAttribute ("name" , String .format ("%s年" , year )).addAttribute ("type" , "year" ).addAttribute ("isParent" , "false" );
126
127
for (int month : year_month .getValue ()){
127
128
Element monthElement = yearElement .addElement ("node" );
128
- if (unfoldCurrentMonth && currentMonth == month ){
129
+ if (unfoldCurrentMonth && Collections . max ( year_month . getValue ()). equals ( month )){ //修改此处bug,发现如果几天没有数据,但新来的一天是新的月的第一天,这样就不能展开文件夹了,修改为最大的月份就会展开
129
130
monthElement .addAttribute ("open" , "true" );//王波的ajax树的属性展开,则该文件夹展开了
130
131
}else {
131
132
monthElement .addAttribute ("open" , "false" );//王波的ajax树的属性关闭,则该文件夹关闭了
@@ -138,7 +139,7 @@ public String createInitTree(){
138
139
ym .set (year , month -1 , 01 );
139
140
140
141
monthElement .addAttribute ("id" ,monthFormat .format (ym .getTime ())).addAttribute ("name" ,String .format ("%s月" ,month )).addAttribute ("type" , "month" ).addAttribute ("isParent" , "true" );
141
- if (unfoldCurrentMonth && currentMonth == month ){
142
+ if (unfoldCurrentMonth && Collections . max ( year_month . getValue ()). equals ( month )){ //修改为最大的月份会自动加载天的数据
142
143
loadDayDataToMonth (monthElement ,todayCalendar );
143
144
}
144
145
}
0 commit comments