[英]Yii2 load modal from on click of link
This is my _form 这是我的_form
<div class="row">
<div class="col-sm-4">
<?= $form->field($model, 'otm_grading_system')->dropdownList(ot\TestGradingSystem::getTestGradingSystem(), [
'prompt' => Yii::t('ot', '--- Select Grading System ---'),
'onchange' => '$.get( "'.Url::toRoute('dependent/get-grading-system').'", { id : $(this).val() }).done(function(data) {
$( "#seeHere").html(data);
});'
]) ?>
</div>
<div class="col-sm-4" id="seeHere">
</div>
</div>
In form dropDownList on change event get url. 在change事件的dropDownList表单中获取url。 show below DependandController.php
在下面显示DependandController.php
class DependentController extends \yii\web\Controller
{
public function actionGetGradingSystem($id)
{
return Html::a('See Here 123', ['test-grading-system/view', 'id' => $id], ['id' => 'seeHereMdl', 'title' => Yii::t('ot', 'View Result')]);
}
}
And this is modal load js 这是模态加载js
<?php
$this->registerJs(
"$(document).on('ready pjax:success', function() {
$('#seeHereMdl').click(function(e){
e.preventDefault();
$('#grading-sys-modal').modal('show')
.find('.modal-content')
.load($(this).attr('href'));
});
});
", $this::POS_HEAD);
?>
<?php
yii\bootstrap\Modal::begin([
'id'=>'grading-sys-modal',
'size' => 'modal-lg'
]);
yii\bootstrap\Modal::end();
?>
My problem is this can't load view file in modal but it redirect to this view page. 我的问题是,无法以模式加载视图文件,但它会重定向到此视图页面。
This is an event handling problem (not related to yii), instead of : 这是一个事件处理问题(与yii不相关),而不是:
$('#seeHereMdl').click(function(e){});
You should simply try : 您应该尝试:
$('body').on('click', '#seeHereMdl', function(e) {});
Read more : Event binding on dynamically created elements? 阅读更多: 在动态创建的元素上进行事件绑定?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.