1
이 함수는 데이터를 처리하고 각 데이터를 폼에 채 웁니다. 그 특정 값을 업데이트하려면이 기능을 통해 두 개의 for 루프를 사용하여 반복 할 수있는 방법이 있는지 궁금jQuery 함수 단순화
//Handling of "regular weeks" (no "blackouts" or empty days)
//Itteration through specific day # to ensure specificity
for (var a = 0; a < data.days.length; a++) {
var default_start_time = data.days[a].default_start_time;
var default_end_time = data.days[a].default_end_time;
var select_start_time = data.days[a].start_time;
var select_end_time = data.days[a].end_time;
var time_chunk = data.days[a].time_chunk_id;
if (data.days[a].day_of_week_Number == 2) {
$("#mondayHead").html("Monday");
$("#mondayDate").html(data.days[a].date);
$("#mondayStart").html(buid(default_start_time, default_end_time, select_start_time));
$("#mondayEndTime").html(buid(default_start_time, default_end_time, select_end_time));
$("#mondayTimeChunkID").val(time_chunk);
if (data.days[a].comment != null) {
var subMonday = data.days[a].comment.substring(0, 10);
//Comment is held not diplayed **to be fixed
$("#mondayCommentLink").html(subMonday + "..." + "<input type='hidden' id='mondayCommentText' name='mondayCommentText' size='10' value=data.days[a].comment />");
}
}
if (data.days[a].day_of_week_Number == 3) {
$("#tuesdayHead").html("Tuesday");
$("#tuesdayDate").html(data.days[a].date);
$("#tuesdayStart").html(buid(default_start_time, default_end_time, select_start_time));
$("#tuesdayEndTime").html(buid(default_start_time, default_end_time, select_end_time));
$("#tuesdayTimeChunkID").val(time_chunk);
if (data.days[a].comment != null) {
var subTuesday = data.days[a].comment.substring(0, 10);
$("#tuesdayCommentLink").html(subTuesday + "...");
}
}
if (data.days[a].day_of_week_Number == 4) {
$("#wednesdayHead").html("Wednesday");
$("#wednesdayDate").html(data.days[a].date);
$("#wednesdayStart").html(buid(default_start_time, default_end_time, select_start_time));
$("#wednesdayEndTime").html(buid(default_start_time, default_end_time, select_end_time));
$("#wednesdayTimeChunkID").val(time_chunk);
if (data.days[a].comment != null) {
var subWednesday = data.days[a].comment.substring(0, 10);
$("#wednesdayCommentLink").html(subWednesday + "...");
}
}
if (data.days[a].day_of_week_Number == 5) {
$("#thursdayHead").html("Thursday");
$("#thursdayDate").html(data.days[a].date);
$("#thursdayStart").html(buid(default_start_time, default_end_time, select_start_time));
$("#thursdayEndTime").html(buid(default_start_time, default_end_time, select_end_time));
$("#thursdayTimeChunkID").val(time_chunk);
if (data.days[a].comment != null) {
var subThursday = data.days[a].comment.substring(0, 10);
$("#thursdayCommentLink").html(subThursday + "...");
}
}
if (data.days[a].day_of_week_Number == 6) {
$("#fridayHead").html("Friday");
$("#fridayDate").html(data.days[a].date);
$("#fridayStart").html(buid(default_start_time, default_end_time, select_start_time));
$("#fridayEndTime").html(buid(default_start_time, default_end_time, select_end_time));
$("#fridayTimeChunkID").val(time_chunk);
if (data.days[a].comment != null) {
var subFriday = data.days[a].comment.substring(0, 10);
$("#fridayCommentLink").html(subFriday + "...");
}
}
if (data.days[a].day_of_week_Number == 7) {
$("#saturdayHead").html("Saturday");
$("#saturdayDate").html(data.days[a].date);
$("#saturdayStart").html(buid(default_start_time, default_end_time, select_start_time));
$("#saturdayEndTime").html(buid(default_start_time, default_end_time, select_end_time));
$("#saturdayTimeChunkID").val(time_chunk);
if (data.days[a].comment != null) {
var subSaturday = data.days[a].comment.substring(0, 10);
$("#saturdayCommentLink").html(subSaturday + "...");
}
}
}
임 : 더 나은 방법 단순히이 코드가 있다면 궁금 해서요. 나는 if
진술을 잔뜩 가지고있는 것이 좋은 습관이 아니며 그것을 볼 때도 우아하다고 생각합니다.
는 http://codereview.stackexchange.com/에이를 게시 해 봅니다. 그것은 "iditis"의 일반적인 경우처럼 보입니다. 대신에 공통 클래스를 사용하는 것을 고려하십시오. – elclanrs