fix js bug
This commit is contained in:
parent
32bd2ffac5
commit
8945e3b64a
|
@ -1,4 +1,30 @@
|
||||||
$(document).ready(function(){
|
$(document).ready(function(){
|
||||||
|
Array.prototype.remove_item_from_array = function(){
|
||||||
|
var result_array = this;
|
||||||
|
for(var i=0;i<arguments.length;i++){
|
||||||
|
if(Array.isArray(arguments[i])){
|
||||||
|
for(var j=0;j<arguments.length;j++){
|
||||||
|
var index = result_array.indexOf(arguments[i][j]);
|
||||||
|
if(index == -1)
|
||||||
|
continue;
|
||||||
|
else{
|
||||||
|
result_array = result_array.slice(0, index).concat(result_array.slice(index + 1, result_array.length));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
var index = result_array.indexOf(arguments[i]);
|
||||||
|
if(index == -1)
|
||||||
|
continue;
|
||||||
|
else{
|
||||||
|
result_array = result_array.slice(0, index).concat(result_array.slice(index + 1, result_array.length));
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
console.log(this)
|
||||||
|
result_array.push = this.push;
|
||||||
|
result_array.remove_item_from_array = this.remove_item_from_array;
|
||||||
|
return result_array;
|
||||||
|
};
|
||||||
$('.cancer_help_btn').append('<i aria-hidden="true" class="fa fa-question"></i>');
|
$('.cancer_help_btn').append('<i aria-hidden="true" class="fa fa-question"></i>');
|
||||||
$('.cancer_help_btn').off("click").on('click',function(){
|
$('.cancer_help_btn').off("click").on('click',function(){
|
||||||
var modal_head = "";
|
var modal_head = "";
|
||||||
|
@ -187,7 +213,6 @@ $(document).ready(function(){
|
||||||
$('tr.'+arguments[0]).css('display','table-row');
|
$('tr.'+arguments[0]).css('display','table-row');
|
||||||
$('tr.tr_show').eq(-1).after($('tr.'+arguments[0]));
|
$('tr.tr_show').eq(-1).after($('tr.'+arguments[0]));
|
||||||
$('tr.'+arguments[0]).addClass('tr_show');
|
$('tr.'+arguments[0]).addClass('tr_show');
|
||||||
console.log(servive_ratio_arr);
|
|
||||||
if(this.length == 1){
|
if(this.length == 1){
|
||||||
$('.addition').css('display','block');
|
$('.addition').css('display','block');
|
||||||
$('#result_text_content .extra-text').css('display','inline-block');
|
$('#result_text_content .extra-text').css('display','inline-block');
|
||||||
|
@ -203,69 +228,57 @@ $(document).ready(function(){
|
||||||
add_choices_str += ('以及'+add_choices_transform[add_choices_transform.length-1])
|
add_choices_str += ('以及'+add_choices_transform[add_choices_transform.length-1])
|
||||||
else
|
else
|
||||||
add_choices_str = add_choices_transform[0];
|
add_choices_str = add_choices_transform[0];
|
||||||
console.log(add_choices_transform);
|
var new_text = '<p class="texts_show">'+'<a>100 位在術後有接受</a><a class="'+arguments[0]+' choices">'+add_choices_str+'</a><a>的婦女中,有 </a>'+'<a class="'+arguments[0]+' Overall_Survival">'+servive_ratio+'</a>'+'<a> 位婦女,術後 </a>'+'<a class="surgery_year">'+year+'</a>'+'<a>年仍為存活(多了</a>'+'<a class="'+arguments[0]+' Additional_Benefit">'+benefit+'</a><a>位)</a>'+'</p>';
|
||||||
var new_text = '<p class="texts_show">'+'<a>100 位在術後有接受'+add_choices_str+'的婦女中,有 </a>'+'<a class="'+arguments[0]+' Overall_Survival">'+servive_ratio+'</a>'+'<a> 位婦女,術後 </a>'+'<a class="surgery_year">'+year+'</a>'+'<a>年仍為存活(多了</a>'+'<a class="'+arguments[0]+' Additional_Benefit">'+benefit+'</a><a>位)</a>'+'</p>';
|
|
||||||
$('#result_text_content .extra-text .texts_show').eq(-1).after(new_text)
|
$('#result_text_content .extra-text .texts_show').eq(-1).after(new_text)
|
||||||
return Array.prototype.push.apply(this, arguments);
|
return Array.prototype.push.apply(this, arguments);
|
||||||
}else{
|
}else{
|
||||||
return Array.prototype.push.apply(this, arguments);
|
return Array.prototype.push.apply(this, arguments);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
Array.prototype.remove_item_from_array = function(){
|
active_treatment.remove_item_from_array = function(){
|
||||||
var result_array = this;
|
if(arguments.length == 1 && !Array.isArray(arguments[0])){
|
||||||
for(var i=0;i<arguments.length;i++){
|
var index = this.indexOf(arguments[0])
|
||||||
if(Array.isArray(arguments[i])){
|
var year = $('#current_year').attr('value');
|
||||||
for(var j=0;j<arguments.length;j++){
|
if(index < this.length - 1){
|
||||||
var index = result_array.indexOf(arguments[i][j]);
|
for(var i = index + 1;i < this.length; i++){
|
||||||
if(index == -1)
|
lpv_real[i] -= lpv_dict[arguments[0]]
|
||||||
continue;
|
var servive_ratio = (Math.exp(lpv_calc[year])**lpv_real[i])*100;
|
||||||
else{
|
var benefit = servive_ratio - servive_ratio_arr[servive_ratio_arr.length - 1];
|
||||||
result_array = result_array.slice(0, index).concat(result_array.slice(index + 1, result_array.length));
|
$('tr.'+active_treatment[i]+' td.Overall_Survival').html(servive_ratio);
|
||||||
|
$('.'+active_treatment[i]+'.Overall_Survival').html(servive_ratio);
|
||||||
|
$('tr.'+active_treatment[i]+' td.Additional_Benefit').html(benefit);
|
||||||
|
$('.'+active_treatment[i]+'.Additional_Benefit').html(benefit);
|
||||||
|
};
|
||||||
|
var add_choices = [];
|
||||||
|
for(var i = 1;i < this.length; i++){
|
||||||
|
if(i != index){
|
||||||
|
add_choices.push(this[i]);
|
||||||
|
var add_choices_transform = [];
|
||||||
|
for(var j = 0;j<add_choices.length;j++){
|
||||||
|
add_choices_transform.push($('[for="'+add_choices[j]+'"]').html())
|
||||||
|
};
|
||||||
|
var add_choices_str = add_choices_transform.slice(0,add_choices_transform.length-1).join('、');
|
||||||
|
if(add_choices_transform.length >= 2)
|
||||||
|
add_choices_str += ('以及'+add_choices_transform[add_choices_transform.length-1])
|
||||||
|
else
|
||||||
|
add_choices_str = add_choices_transform[0];
|
||||||
|
$('.'+active_treatment[i]+'.choices').html(add_choices_str);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}else{
|
|
||||||
var index = result_array.indexOf(arguments[i]);
|
|
||||||
if(index == -1)
|
|
||||||
continue;
|
|
||||||
else{
|
|
||||||
result_array = result_array.slice(0, index).concat(result_array.slice(index + 1, result_array.length));
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
$('tr.'+arguments[0]+' td.Overall_Survival').html('-');
|
||||||
return result_array;
|
$('tr.'+arguments[0]+' td.Additional_Benefit').html('-');
|
||||||
};
|
$('tr.'+arguments[0]).css('display','none');
|
||||||
active_treatment.remove_item_from_array = function(){
|
$('tr.'+arguments[0]).removeClass('tr_show');
|
||||||
if(arguments.length == 1){
|
$('a.'+arguments[0]).eq(0).parent().remove();
|
||||||
var year = $('#current_year').attr('value');
|
lpv_real = lpv_real.remove_item_from_array(lpv_real[index]);
|
||||||
var lpv_current = lpv_real[lpv_real.length-1]+lpv_dict[arguments[0]];
|
console.log(lpv_real);
|
||||||
lpv_real.push(lpv_current);
|
servive_ratio_arr = servive_ratio_arr.remove_item_from_array(servive_ratio_arr[index]);
|
||||||
var servive_ratio = (Math.exp(lpv_calc[year])**lpv_current)*100;
|
if(this.length == 2){
|
||||||
var benefit = servive_ratio - servive_ratio_arr[servive_ratio_arr.length - 1];
|
$('.addition').css('display','none');
|
||||||
servive_ratio_arr.push(servive_ratio);
|
$('#result_text_content .extra-text').css('display','none');
|
||||||
$('tr.'+arguments[0]+' td.Overall_Survival').html(servive_ratio);
|
|
||||||
$('tr.'+arguments[0]+' td.Additional_Benefit').html(benefit);
|
|
||||||
$('tr.'+arguments[0]).css('display','table-row');
|
|
||||||
$('tr.tr_show').eq(-1).after($('tr.'+arguments[0]));
|
|
||||||
$('tr.'+arguments[0]).addClass('tr_show');
|
|
||||||
console.log(servive_ratio_arr);
|
|
||||||
if(this.length == 1){
|
|
||||||
$('.addition').css('display','block');
|
|
||||||
$('#result_text_content .extra-text').css('display','inline-block');
|
|
||||||
}
|
|
||||||
var add_choices = this.slice(1,this.length);
|
|
||||||
add_choices.push(arguments[0]);
|
|
||||||
var add_choices_transform = [];
|
|
||||||
for(var i = 0;i<add_choices.length;i++){
|
|
||||||
add_choices_transform.push($('[for="'+add_choices[i]+'"]').html())
|
|
||||||
};
|
};
|
||||||
var add_choices_str = add_choices_transform.slice(0,add_choices_transform.length-1).join('、');
|
console.log(arguments[0]);
|
||||||
if(add_choices_transform.length >= 2)
|
|
||||||
add_choices_str += ('以及'+add_choices_transform[add_choices_transform.length-1])
|
|
||||||
else
|
|
||||||
add_choices_str = add_choices_transform[0];
|
|
||||||
console.log(add_choices_transform);
|
|
||||||
var new_text = '<p class="texts_show">'+'<a>100 位在術後有接受'+add_choices_str+'的婦女中,有 </a>'+'<a class="'+arguments[0]+' Overall_Survival">'+servive_ratio+'</a>'+'<a> 位婦女,術後 </a>'+'<a class="surgery_year">'+year+'</a>'+'<a>年仍為存活(多了</a>'+'<a class="'+arguments[0]+' Additional_Benefit">'+benefit+'</a><a>位)</a>'+'</p>';
|
|
||||||
$('#result_text_content .extra-text .texts_show').eq(-1).after(new_text)
|
|
||||||
return Array.prototype.remove_item_from_array.apply(this, arguments);
|
return Array.prototype.remove_item_from_array.apply(this, arguments);
|
||||||
}else{
|
}else{
|
||||||
return Array.prototype.remove_item_from_array.apply(this, arguments);
|
return Array.prototype.remove_item_from_array.apply(this, arguments);
|
||||||
|
@ -277,16 +290,15 @@ $(document).ready(function(){
|
||||||
if(!active_treatment.includes($(this).parent().attr('id'))){
|
if(!active_treatment.includes($(this).parent().attr('id'))){
|
||||||
active_treatment.push($(this).parent().attr('id'))
|
active_treatment.push($(this).parent().attr('id'))
|
||||||
console.log($(this).parent().attr('id'))
|
console.log($(this).parent().attr('id'))
|
||||||
}
|
};
|
||||||
})
|
});
|
||||||
$('#'+treatmeny_method[i]+' .cancer_table_btn').eq(0).click(function(){
|
$('#'+treatmeny_method[i]+' .cancer_table_btn').eq(0).click(function(){
|
||||||
if(!active_treatment.includes($(this).parent().attr('id'))){
|
if(active_treatment.includes($(this).parent().attr('id'))){
|
||||||
//a.indexOf(3)
|
active_treatment = active_treatment.remove_item_from_array($(this).parent().attr('id'));
|
||||||
active_treatment.push($(this).parent().attr('id'))
|
console.log(active_treatment);
|
||||||
console.log($(this).parent().attr('id'))
|
};
|
||||||
}
|
});
|
||||||
})
|
};
|
||||||
}
|
|
||||||
$('#current_year').change(function(){
|
$('#current_year').change(function(){
|
||||||
$('.surgery_year').html($(this).attr('value'));
|
$('.surgery_year').html($(this).attr('value'));
|
||||||
$('.cancer_years').removeClass('active');
|
$('.cancer_years').removeClass('active');
|
||||||
|
@ -304,9 +316,6 @@ $(document).ready(function(){
|
||||||
$('.'+active_treatment[i]+'.Additional_Benefit').html(benefit);
|
$('.'+active_treatment[i]+'.Additional_Benefit').html(benefit);
|
||||||
}
|
}
|
||||||
$('.'+active_treatment[0]+'.Overall_Survival').html(servive_ratio_arr[0]);
|
$('.'+active_treatment[0]+'.Overall_Survival').html(servive_ratio_arr[0]);
|
||||||
/*for(var i = 0;i<treatmeny_method.length;i++){
|
|
||||||
$('.'+treatmeny_method[i]+'["name='+yes+'"]').attr('value') == 1
|
|
||||||
}*/
|
|
||||||
$('.survive_person').html(servive_ratio);
|
$('.survive_person').html(servive_ratio);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue