1
我正在创建库会员表单,在此形式中,学生列表通过选择选项中的ajax请求进行填充。现在我需要禁用已经是图书馆成员的学生选项。如果选项值已存在,则禁用选择选项
表单视图
<div class="form-group">
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-asterisk" aria-hidden="true"></i> <i class="fa fa-calendar" aria-hidden="true"></i> <?php echo get_phrase('_batch'); ?></span>
<select id="batch_result_holder" name="batch_result_holder" onchange="return get_batchs_students(this.value)" data-plugin="select2" required>
<option disabled selected value=""> <?php echo get_phrase('select_programs_first'); ?></option>
</select>
</div>
</div><!-- form-group -->
<div class="form-group">
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-asterisk" aria-hidden="true"></i> <i class="fa fa-user" aria-hidden="true"></i> <?php echo get_phrase('_student'); ?></span>
<select id="student_result_holder" name="student_result_holder" data-plugin="select2" >
<option disabled selected> <?php echo get_phrase('select_batch_first'); ?></option>
</select>
</div>
</div><!-- form-group -->
Ajax代码来拉学生信息
function get_batchs_students(batch_result_holder){
var program_id = $('#program_id').val();
$.ajax({
type:"POST",
url: '<?php echo base_url();?>index.php?admin/get_batch_students_without_assigned/',
data:{batch_result_holder: batch_result_holder, program_id:program_id},
success: function(response)
{
jQuery('#student_result_holder').html(response);
}
});
}
控制器,拉学生名单
function get_batch_students_without_assigned($program_id, $batch_id, $status){
$program_id = $this->input->post('program_id');
$batch_id = $this->input->post('batch_result_holder');
$students = $this->crud_model->get_student_list_without_section($program_id, $batch_id, 1);
$assigned_student = $this->crud_model->get_assigned_students();
echo '<option value="" selected disabled> select from list below </option>';
foreach($assigned_student as $row2):
foreach($students as $row){
echo '<option value="' . $row['student_id'] . '"';
if($row['student_id'] == $row2['type_id']):
echo 'disabled';
endif;
echo '>';
echo $row['name'];
echo '</option>';
}
endforeach;
}
但上述控制器会遍历所有学生和分配的学生,并输出关于禁用和非禁用格式的相同学生选项。那么,我如何防止这个控制器显示所有学生都是已经是会员的残疾学生。
output of the above controller
谢谢你这么多@Gavriel ......其工作现在:) –