Jquery yii使用右连接获取数据时重新加载网格
假设一家公司有多个部门。 Company是division表中的外键 我有两个要求: 1-更改第一个(工作罚款)的第二个下拉列表。Jquery yii使用右连接获取数据时重新加载网格,jquery,html,select,yii,cgridview,Jquery,Html,Select,Yii,Cgridview,假设一家公司有多个部门。 Company是division表中的外键 我有两个要求: 1-更改第一个(工作罚款)的第二个下拉列表。 2-在更改公司下拉列表或第一个下拉列表时重新加载网格视图,就像我更改公司字段的下拉列表(公司表中的主键和部门表中的外键),重新加载的网格显示在第一个下拉列表中选择的公司的数据 这是我的模型 class Divisions extends CActiveRecord { public function relations() { retur
2-在更改公司下拉列表或第一个下拉列表时重新加载网格视图,就像我更改公司字段的下拉列表(公司表中的主键和部门表中的外键),重新加载的网格显示在第一个下拉列表中选择的公司的数据 这是我的模型
class Divisions extends CActiveRecord
{
public function relations() {
return array(
'company' => array(self::BELONGS_TO, 'Companies', 'CompanyID'),
'fiscalperiods' => array(self::HAS_MANY, 'Fiscalperiods', 'DivisionID'),
'regions' => array(self::HAS_MANY, 'Regions', 'DivisionID'),
);
}
}
这是我在admin.php
中的外部文件,用于下拉列表
<div class="row">
<?php
$form = $this->beginWidget('CActiveForm', array(
'action' => Yii::app()->createUrl($this->route),
'method' => 'get',
));
?>
<div class="row">
</div>
<div class="row">
<div class="span2">
Choose Company
</div>
<div class="span2 offset1">
Choose Division
</div>
</div>
<div class="row">
<div class="span2">
<?php
$modelCompany = new Companies();
echo CHtml::activeDropDownList($modelCompany, 'Name', Chtml::listData(Companies::model()->findAll(), 'CompanyID', 'Name'), array(
'ajax' => array(
'type' => 'POST', //request type
'url' => CController::createUrl('divisions/generatedivisions'), //url to call.
'update' => '#Divisions_Name',
)));
?>
</div>
<div class="span2 offset1">
<?php
$modelDivisions = new Divisions();
echo CHtml::activeDropDownList($modelDivisions, 'Name', Chtml::listData(Divisions::model()->findAll(), 'DivisionID', 'Name'), array(
'ajax' => array(
'type' => 'GET', //request type
)));
?>
</div>
</div>
<?php $this->endWidget(); ?>
选择公司
选择除法
您可以在没有ajax的情况下解决它。 我不擅长前端。但这是我可以帮助你的
$companies = array(
// id company => name
1 => 'one',
2 => 'two',
3 => 'three',
4 => 'etc'
);
$secondList = array(
// id company
1 => array(
1 => 'Requirements one 1',
2 => 'Requirements one 2'
),
2 => array(
// sub id => name
4 => 'Requirements two 1',
5 => 'Requirements two 2'
)
);
你的看法:
<?php
echo CHtml::activeDropDownList(new Companies(), 'Name', $companies);
$show = true;
?>
<select id="second-select" name="second-select">
<?php foreach ($secondList as $companyId => $arrayOptions) : ?>
<?php foreach ($arrayOptions as $key => $option) : ?>
<option
data-company="<?= $companyId ?>"
<?php if ($show == false) : ?>hidden="hidden" <?php endif ?>
value="<?= $key ?>"><?= $option ?>
</option>
<?php endforeach ?>
<?php if ($show == true) $show = false; ?>
<?php endforeach ?>
</select>
尝试依赖下拉列表!
$(document).ready(function() {
$('#Companies_Name').on('change', function() {
var companyId = $(this).val();
var options = $('#second-select option');
options.attr('hidden', 'hidden');
options = options.filter('*[data-company="' + companyId + '"]');
options.removeAttr('hidden');
options.first().attr('selected','selected');
});
});