当您在类表中选择名称时,付款条件将基于sql表(请参见sql表),这使我很难确定如何建立下拉依赖关系(付款条件基于选定的类名)。最后一张表)基于类级别的选择。我认为我的JavaScript和CI模型有问题。我在这个codeigniter活动记录中非常陌生,请帮助我解决我的问题,并非常感谢您
CLASS TABLE
classes
|-------|------------------|
| id | Name |
|-------|------------------|
| 1 | Grade 1 |
|-------|------------------|
| 2 | Grade 2 |
|-------|------------------|
付款条款表
payment_terms
|--------|------------------------------------|
| id | payment_terms |
|--------|------------------------------------|
| 1 | Grade 1 Full Payment |
|--------|------------------------------------|
| 2 | Grade 1 Quarterly Payment |
|--------|------------------------------------|
| 3 | Grade 2 Full Payment |
|--------|------------------------------------|
| 4 | Grade 2 Quarterly Payment |
|--------|------------------------------------|
学术年表
academic_year
|--------|------------------------------------|
| id | academic_year |
|--------|------------------------------------|
| 1 | 2018-2019 |
|--------|------------------------------------|
学术年度和付款条款表
academic_year_payment_terms
|--------|------------------|------------------|
| id | academic_year_id | Payment_term_id |
|--------|------------------|------------------|
| 1 | 1 | 1 |
|--------|------------------|------------------|
| 2 | 1 | 2 |
|--------|------------------|------------------|
| 3 | 1 | 3 |
|--------|------------------|------------------|
| 4 | 1 | 4 |
|--------|------------------|------------------|
学术年度付款条款和分类表
academic_year_payment_terms_class
|--------|-----------------------------|------------------|
| id | academic_year_payment_terms | class_id |
|--------|-----------------------------|------------------|
| 1 | 1 | 1 |
|--------|-----------------------------|------------------|
| 2 | 2 | 1 |
|--------|-----------------------------|------------------|
| 3 | 3 | 2 |
|--------|-----------------------------|------------------|
| 4 | 4 | 2 |
|--------|-----------------------------|------------------|
我的Codeigniter视图
<div class="form-group">
<select id="class_id" name="class_id" class="form-control" >
<option value=""><?php echo $this->lang->line('select'); ?></option>
<?php
foreach ($classlist as $class) { ?>
<option value="<?php echo $class['id'] ?>"<?php
if (set_value('class_id') == $class['id']){
echo "selected =selected";
}
?>><?php echo $class['class'] ?></option>
<?php
$count++;
}
?>
</select>
</div>
<div class="form-group">
<select class="form-control" id="academic_year_payment_terms_id" name="academic_year_payment_terms_id">
</select>
</div>
我的JavaScript
<script type="text/javascript">
function getAcademicPaymentTermsByClass(class_id, academic_year_payment_terms_id {
if (class_id != "" && academic_year_payment_terms_id != "") {
$('#academic_year_payment_terms_id').html("");
var base_url = '<?php echo base_url() ?>';
var div_data = '<option value=""><?php echo $this->lang->line('select'); ?></option>';
$.ajax({
type: "GET",
url: base_url + "enrollment/fetchPaymentTermsByClass",
data: {'class_id': class_id},
dataType: "json",
success: function (data) {
$.each(data, function (i, obj)
{
var sel = "";
if (academic_year_payment_terms_id == obj.academic_year_payment_terms_id) {
sel = "selected";
}
div_data += "<option value=" + obj.academic_year_payment_terms_id+ " " + sel + ">" + obj.payment_terms + "</option>";
});
$('#academic_year_payment_terms_id').append(div_data);
}
});
}
}
$(document).ready(function () {
var class_id = $('#class_id').val();
var academic_year_payment_terms_id = '<?php echo set_value('academic_year_payment_terms_id') ?>';
getAcademicPaymentTermsByClass(class_id, academic_year_payment_terms_id);
$(document).on('change', '#class_id', function (e) {
$('#academic_year_payment_terms_id').html("");
var class_id = $(this).val();
var base_url = '<?php echo base_url() ?>';
var div_data = '<option value=""><?php echo $this->lang->line('select'); ?></option>';
$.ajax({
type: "GET",
url: base_url + "enrollment/fetchPaymentTermsByClass",
data: {'class_id': class_id},
dataType: "json",
success: function (data) {
$.each(data, function (i, obj)
{
div_data += "<option value=" + obj.academic_year_payment_terms_id' + ">" + obj.payment_terms' + "</option>";
});
$('#academic_year_payment_terms_id').append(div_data);
}
});
});
});
我的注册负责人
function fetchPaymentTermsByClass() {
$class_id = $this->input->get('class_id');
$data = $this->Enrollment_model->getPaymentTermsByClass($class_id);
echo json_encode($data);
}
我的注册模型
public function getPaymentTermsByClass($classid){
$this->db->select('academic_year_payment_terms_class.id, academic_year_payment_terms_class.academic_year_payment_terms_id, academic_year_payment_terms.payment_terms');
$this->db->from('academic_year_payment_terms_class');
$this->db->join('academic_year_payment_terms', 'academic_year_payment_terms.id = academic_year_payment_terms_class.academic_year_payment_terms_id');
$this->db->where('academic_year_payment_terms_class.class_id', $classid);
$this->db->order_by('academic_year_payment_terms_class.id');
$query = $this->db->get();
return $query->result_array();
}