Javascript 代码点火器活动记录中的下拉依赖项
我很难弄清楚如何建立一个下拉依赖关系(付款条件基于选定的类名),当您在类表中选择名称时,您将在类级别的sql表(见最后一个表)基础选择基础上创建付款条件。我认为我的javascript和CI模型有问题。我是这个codeigniter activerecord的新手,请帮助我解决我的问题,并提前向您表示感谢 类表Javascript 代码点火器活动记录中的下拉依赖项,javascript,php,codeigniter,activerecord,Javascript,Php,Codeigniter,Activerecord,我很难弄清楚如何建立一个下拉依赖关系(付款条件基于选定的类名),当您在类表中选择名称时,您将在类级别的sql表(见最后一个表)基础选择基础上创建付款条件。我认为我的javascript和CI模型有问题。我是这个codeigniter activerecord的新手,请帮助我解决我的问题,并提前向您表示感谢 类表 classes |-------|------------------| | id | Name | |-------|----------
classes
|-------|------------------|
| id | Name |
|-------|------------------|
| 1 | Grade 1 |
|-------|------------------|
| 2 | Grade 2 |
|-------|------------------|
academic_year_payment_terms_class
|--------|-----------------------------|------------------|
| id | academic_year_payment_terms | class_id |
|--------|-----------------------------|------------------|
| 1 | 1 | 1 |
|--------|-----------------------------|------------------|
| 2 | 2 | 1 |
|--------|-----------------------------|------------------|
| 3 | 3 | 2 |
|--------|-----------------------------|------------------|
| 4 | 4 | 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_payment_terms
|--------|------------------|------------------|
| id | academic_year_id | Payment_term_id |
|--------|------------------|------------------|
| 1 | 1 | 1 |
|--------|------------------|------------------|
| 2 | 1 | 2 |
|--------|------------------|------------------|
| 3 | 1 | 3 |
|--------|------------------|------------------|
| 4 | 1 | 4 |
|--------|------------------|------------------|
学年表
academic_year
|--------|------------------------------------|
| id | academic_year |
|--------|------------------------------------|
| 1 | 2018-2019 |
|--------|------------------------------------|
学年及付款条件表
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_payment_terms
|--------|------------------|------------------|
| id | academic_year_id | Payment_term_id |
|--------|------------------|------------------|
| 1 | 1 | 1 |
|--------|------------------|------------------|
| 2 | 1 | 2 |
|--------|------------------|------------------|
| 3 | 1 | 3 |
|--------|------------------|------------------|
| 4 | 1 | 4 |
|--------|------------------|------------------|
学年付款条件和班级表
classes
|-------|------------------|
| id | Name |
|-------|------------------|
| 1 | Grade 1 |
|-------|------------------|
| 2 | Grade 2 |
|-------|------------------|
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>
我的注册模式
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();
}
您何时调用此函数getAcademicPaymentTermsByClass();使用jquery和相同的函数代替javascipt,用于类_id的onchange事件,这应该可以工作。我的CI模型如何?CI模型函数在控制器soi中调用?我的意思是模型中的代码我不知道是否正确,因为我调用了我文章顶部的所有表。。。javascript在多对多关系中功能良好,但在本例中,我调用了一个多对多表,连接表的一行连接到一对多表中。进行更改后运行应用程序。如果您得到错误,您可以调试