我有一个MySQL表和模型
,其中包含字段[data-component='sidebar'] .first-menu {
position: absolute;
top: 0px;
left: 0;
height: 100%;
background-color: #292a2c;
width: 75px;
overflow: hidden;
transition: width 0.5s;
}
[data-component='sidebar'] .first-menu a {
color: white;
}
[data-component='sidebar'] .first-menu i {
font-size: 24px;
}
[data-component='sidebar'] .first-menu span {
font-size: 14px;
white-space: nowrap;
font-family: 'Open Sans', sans-serif;
opacity: 0;
visibility: hidden;
color: aliceblue
}
[data-component='sidebar'] .first-menu:hover span {
opacity: 1;
visibility: visible;
}
[data-component='sidebar'] .first-menu .list-group-item {
border-radius: 0;
position: relative;
}
[data-component='sidebar'] .first-menu .list-group-item:hover {
background-color: #9932CC;
}
[data-component='sidebar'] .first-menu:hover {
width: 190px;
}
[data-component='sidebar'] .list-group-item {
font-size: 14px;
background: #9932CC
}
[data-component='sidebar'] .submenu {
/* position: absolute;
left: 110px;
width: 100%;
top: 0px;
background-color: #9932CC;
height: 100%;
opacity: 0;
visibility: hidden;
transition: opacity 600ms, visibility 600ms;
*/
position: fixed;
left: 195px;
width: 195px;
top: 60px;
background-color:#9932CC;
height: 100%;
opacity: 0;
visibility: hidden;
transition: opacity 600ms, visibility 600ms;
}
[data-component='sidebar'] .submenu .list-group-item {
margin-top: 8px;
}
[data-component='sidebar'] .first-menu li:hover .submenu {
visibility: visible;
opacity: 1;
}
[data-component='sidebar'] .list-group-item {
background-color: transparent;
border: none;
border-radius: 0;
}
[data-component='sidebar'] .first-menu {
position: absolute;
top: 0px;
left: 0;
height: 100%;
background-color: #292a2c;
width: 75px;
overflow: hidden;
transition: width 0.5s;
}
[data-component='sidebar'] .first-menu a {
color: white;
}
[data-component='sidebar'] .first-menu i {
font-size: 24px;
}
[data-component='sidebar'] .first-menu span {
font-size: 14px;
white-space: nowrap;
font-family: 'Open Sans', sans-serif;
opacity: 0;
visibility: hidden;
color: aliceblue
}
[data-component='sidebar'] .first-menu:hover span {
opacity: 1;
visibility: visible;
}
[data-component='sidebar'] .first-menu .list-group-item {
border-radius: 0;
position: relative;
}
[data-component='sidebar'] .first-menu .list-group-item:hover {
background-color: #9932CC;
}
[data-component='sidebar'] .first-menu:hover {
width: 190px;
}
[data-component='sidebar'] .list-group-item {
font-size: 14px;
background: #9932CC
}
[data-component='sidebar'] .submenu {
/* position: absolute;
left: 110px;
width: 100%;
top: 0px;
background-color: #9932CC;
height: 100%;
opacity: 0;
visibility: hidden;
transition: opacity 600ms, visibility 600ms;
*/
position: fixed;
left: 195px;
width: 195px;
top: 60px;
background-color:#9932CC;
height: 100%;
opacity: 0;
visibility: hidden;
transition: opacity 600ms, visibility 600ms;
}
[data-component='sidebar'] .submenu .list-group-item {
margin-top: 8px;
}
[data-component='sidebar'] .first-menu li:hover .submenu {
visibility: visible;
opacity: 1;
}
[data-component='sidebar'] .list-group-item {
background-color: transparent;
border: none;
border-radius: 0;
}
我还有另一个表/模型
,其中也包含 <div data-component="sidebar">
<div class="sidebar">
<ul class="list-group flex-column d-inline-block first-menu">
<li class="list-group-item pl-3 py-2">
<a href="#"><i class="fa fa-desktop" aria-hidden="true"><span class="ml-2 align-middle">Dashboard</span></i></a>
</li> <!-- /.list-group-item -->
<li class="list-group-item pl-3 py-2">
<a href="#"><i class="fab fa-accusoft" aria-hidden="true"><span class="ml-2 align-middle">Groups & Rec</span></i></a>
</li> <!-- /.list-group-item -->
<li class="list-group-item pl-3 py-2">
<a href="#">
<i class="fab fa-bandcamp" aria-hidden="true"><span class="ml-2 align-middle">Platforms</span></i>
</a>
</li> <!-- /.list-group-item -->
<li class="list-group-item pl-3 py-2">
<a href="#"><i class="fas fa-truck" aria-hidden="true"><span class="ml-2 align-middle">Delivery</span></i></a>
<ul class="list-group flex-column d-inline-block submenu">
<li class="list-group-item pl-4">
<a href="#" class="">Report Dome</a>
</li>
<li class="list-group-item pl-4">
<a href="#" class="">Deploy Rappro</a>
</li>
</ul>
</li>
<li class="list-group-item pl-3 py-2">
<a href="#"><i class="fas fa-tools" aria-hidden="true"><span class="ml-2 align-middle">Tools</span></i></a>
<ul class="list-group flex-column d-inline-block submenu">
<li class="list-group-item pl-4">
<a href="#" class="">Duplicate Platform</a>
</li>
</ul>
</li>
<li class="list-group-item pl-3 py-2">
<a href="#"><i class="fa fa-crosshairs" aria-hidden="true"><span class="ml-2 align-middle">Tests</span></i></a>
<ul class="list-group flex-column d-inline-block submenu">
<li class="list-group-item pl-4">
<a href="#" class="">Rules</a>
</li>
<li class="list-group-item pl-4">
<a href="#" class="">Execution</a>
</li>
</ul>
</li>
<li class="list-group-item pl-3 py-2">
<a href="#"><i class="far fa-flag" aria-hidden="true"><span class="ml-2 align-middle">Report</span></i></a>
<ul class="list-group flex-column d-inline-block submenu">
<li class="list-group-item pl-4">
<a href="#" class="">Active List Report</a>
</li>
</ul>
</li>
<li class="list-group-item pl-3 py-2">
<a href="#"><i class="far fa-flag" aria-hidden="true"><span class="ml-2 align-middle">Statistics</span></i></a>
<ul class="list-group flex-column d-inline-block submenu">
<li class="list-group-item pl-4">
<a href="#" class="">Execution</a>
</li>
</ul>
</li>
<li class="list-group-item pl-3 py-2">
<a href="#">
<i class="fas fa-user-check" aria-hidden="true"><span class="ml-2 align-middle">Astreinte</span></i>
</a>
</li>
</ul> <!-- /.first-menu -->
</div> <!-- /.sidebar -->
</div>
<div data-component="sidebar">
<div class="sidebar">
<ul class="list-group flex-column d-inline-block first-menu">
<li class="list-group-item pl-3 py-2">
<a href="#"><i class="fa fa-desktop" aria-hidden="true"><span class="ml-2 align-middle">Dashboard</span></i></a>
</li> <!-- /.list-group-item -->
<li class="list-group-item pl-3 py-2">
<a href="#"><i class="fab fa-accusoft" aria-hidden="true"><span class="ml-2 align-middle">Groups & Rec</span></i></a>
</li> <!-- /.list-group-item -->
<li class="list-group-item pl-3 py-2">
<a href="#">
<i class="fab fa-bandcamp" aria-hidden="true"><span class="ml-2 align-middle">Platforms</span></i>
</a>
</li> <!-- /.list-group-item -->
<li class="list-group-item pl-3 py-2">
<a href="#"><i class="fas fa-truck" aria-hidden="true"><span class="ml-2 align-middle">Delivery</span></i></a>
<ul class="list-group flex-column d-inline-block submenu">
<li class="list-group-item pl-4">
<a href="#" class="">Report Dome</a>
</li>
<li class="list-group-item pl-4">
<a href="#" class="">Deploy Rappro</a>
</li>
</ul>
</li>
<li class="list-group-item pl-3 py-2">
<a href="#"><i class="fas fa-tools" aria-hidden="true"><span class="ml-2 align-middle">Tools</span></i></a>
<ul class="list-group flex-column d-inline-block submenu">
<li class="list-group-item pl-4">
<a href="#" class="">Duplicate Platform</a>
</li>
</ul>
</li>
<li class="list-group-item pl-3 py-2">
<a href="#"><i class="fa fa-crosshairs" aria-hidden="true"><span class="ml-2 align-middle">Tests</span></i></a>
<ul class="list-group flex-column d-inline-block submenu">
<li class="list-group-item pl-4">
<a href="#" class="">Rules</a>
</li>
<li class="list-group-item pl-4">
<a href="#" class="">Execution</a>
</li>
</ul>
</li>
<li class="list-group-item pl-3 py-2">
<a href="#"><i class="far fa-flag" aria-hidden="true"><span class="ml-2 align-middle">Report</span></i></a>
<ul class="list-group flex-column d-inline-block submenu">
<li class="list-group-item pl-4">
<a href="#" class="">Active List Report</a>
</li>
</ul>
</li>
<li class="list-group-item pl-3 py-2">
<a href="#"><i class="far fa-flag" aria-hidden="true"><span class="ml-2 align-middle">Statistics</span></i></a>
<ul class="list-group flex-column d-inline-block submenu">
<li class="list-group-item pl-4">
<a href="#" class="">Execution</a>
</li>
</ul>
</li>
<li class="list-group-item pl-3 py-2">
<a href="#">
<i class="fas fa-user-check" aria-hidden="true"><span class="ml-2 align-middle">Astreinte</span></i>
</a>
</li>
</ul> <!-- /.first-menu -->
</div> <!-- /.sidebar -->
</div>
假设resume
表已经填充
'resume_id', 'lao', 'persen', 'eom', 'tgt_perpetugas' and 'tgt_pergeseran'
当我以resumes
形式输入数据时,当我通过与'resumes_id', 'lao', 'persen', 'eom', 'tgt_perpetugas' and 'tgt_pergeseran'
表相关的下拉字段选择resume
时,我想要相关的
'resume_id', 'lao', 'persen', 'eom', 'tgt_perpetugas','tgt_pergeseran'
个要自动填写的字段。我的reference,但“ ajax请求出错”。如何自动将数据从一种形式输入到另一种形式yii2 如何解决错误或有建议?
我用于_resumes的_form.php看起来像这样
resumes
在ResumesController中,我添加了。这个:
'lao'
答案 0 :(得分:0)
我了解到您想要字段
lao
针对Resume
模型中保存的Resumes
,该字段与lao
形式Select2
字段中的dropdown()相匹配。
如果正确,那么您首先需要使用select2:select
事件onchange
,而不是使用传统的Select2
事件。对<?= $form->field($model, 'lao')->widget(Select2::classname(), [
'data' => ArrayHelper::map(Lao::find()->all(),'lao_id','lao_id'),
'language' => 'en',
'options' => ['placeholder' => 'Pilih LAO'],
'pluginOptions' => [
'allowClear' => true
],
'pluginEvents'=>[
'select2:select' => 'function(e){getRelatedFields(e.params.data.id);}',
]
]); ?>
和视图顶部的脚本进行一些更改。
用以下内容替换您的select2
$routeAjax = \yii\helpers\Url::toRoute("resume/resumes");
$js=<<<JS
function getRelatedFields(lao_id){
$.ajax({
url: '$routeAjax',
dataType: 'json',
method: 'GET',
data: {id: lao_id},
success: function (data, textStatus, jqXHR) {
$('#resumes-persen').val(data.persen);
$('#resumes-eom').val(data.eom);
$('#resumes-tgt_perpetugas').val(data.tgt_perpetugas);
$('#resumes-tgt_pergeseran').val(data.tgt_pergeseran);
},
beforeSend: function (xhr) {
alert('loading!');
},
error: function (jqXHR, textStatus, errorThrown) {
console.log('An error occured!');
alert('Error in ajax request'+textStatus'\n'+errorThrown);
}
});
}
JS;
$this->registerJs($js, \yii\web\View::POS_READY);
用以下内容替换视图顶部的脚本
Resume
然后,当您选择任何选项时,您要填充从 Resumes
模型到 ActiveForm
lao
在Resume
下拉菜单中。您应该在id
模型中而不是Resumes
模型中的public function actionResumes($id)
{
// you may need to check whether the entered ID is valid or not
$model = \app\models\Resume::findOne(['lao' => $id]);
return \yii\helpers\Json::encode([
'eom' => $model->eom,
'persen' => $model->persen,
'tgt_pergeseran' => $model->tgt_pergeseran,
'tgt_perpetugas' => $model->tgt_perpetugas
]);
}
中获取老挝。
因此,用以下内容替换您的操作
YYYYMMDD