在我的工单表单中,我有一个员工的dropDownList,在员工模型中,我有employee_status,它是“可用”和“不可用”。
如果我将该员工的状态更改为“不可用”,我如何将其从dropDownList in Ticket表单中自动删除?
工单中的员工下拉列表
<?= $form->field($model, 'employee_id')->dropDownlist(
ArrayHelper::map(Employee::find()->all(), 'id', 'employee_name'),
[
'prompt' => 'Select Employee ID',
'style' => 'width:200px'
]); ?>发布于 2017-12-14 01:53:58
我终于明白了
<?= $form->field($model, 'employee_id')->dropDownlist(
ArrayHelper::map(Employee::find()->where(['status' => 'Available'])->all(), 'id', 'employee_name'),
[
'prompt' => 'Select Employee ID',
'style' => 'width:200px'
]); ?>发布于 2017-12-14 20:57:13
您需要根据视图文件中的以下代码为get employee list创建一个dependent dropdown,用于创建dependent dropdown :-
use yii\helpers\ArrayHelper;
echo $form->field($model, 'employee_status')->dropDownList([0=>'Available' , 1 => 'Not Available'],
[
'prompt' => 'Select Employee Status',
'style' => 'width:200px',
'onchange'=>'$.post( "'.Yii::$app->urlManager->createUrl('site/get-employee?status=').'"+$(this).val(), function( data ) {
$( "select#employee-employee_id" ).html( data );
});']);
<?= $form->field($model, 'employee_id')->dropDownlist(
ArrayHelper::map(Employee::find()->all(), 'id', 'employee_name'),
[
'prompt' => 'Select Employee ID',
'style' => 'width:200px'
]); ?>现在为get data for child dropdown编写一个控制器操作。控制器动作代码如下:- SiteController.php
public function actionGetEmployee($status)
{
$employee= \common\models\Employee::find()
->where(['status' => $status])
->orderBy('id DESC')
->all();
if (!empty($employee)) {
foreach($employee as $employee) {
echo "<option value='".$employee->id."'>".$employee->name."</option>";
}
} else {
echo "<option>-</option>";
}
}注意:根据您的代码更改模型名称空间。
发布于 2017-12-14 00:40:16
使用您指定的条件执行查找查询。
因为我们只希望列表中有可用的员工,所以我们可以这样写:
Employee::find('status=:status', [
':status' => 'Available'
])->all();https://stackoverflow.com/questions/47797640
复制相似问题