我有父页面,有两个子视图_sectionhead.php和_classteacher.php当用户从dropdwon中选择时,我需要将renderPartial渲染到那些子视图中如何做到这一点
这是我的创作
如果有其他方式我想知道它。我需要快速帮助
答案 0 :(得分:1)
假设您使用的是HTML,请在HTML代码中添加以下内容
<option onClick="fnCallPage('classteacher')">class teacher</option>
<option onClick="fnCallPage('Section')">Section</option>
在Javascript代码中添加以下内容:
function fnCallPage(param){
//Javascript code for sending
}
答案 1 :(得分:1)
基于@Fraz解决方案:
<强> HTML 强>:
<option onClick="fnCallPage('_classteacher')">class teacher</option>
<option onClick="fnCallPage('_sectionhead')">Section</option>
<div id="divContainerPartial"></div> <!-- View rendered container -->
<强>的Javascript 强>:
function fnCallPage(param){
$.ajax({
url: '<?php echo Yii::app()->createUrl('yourModel/renderPageByAjax');?>/' + param,
type: 'GET',
success: function(html){
$('#divContainerPartial').html(html);
},
error: function(data){
alert('Error loading a '+param+' view.');
}
});
}
<强>控制器强>:
/**
* @param $view String : View name to render.
*/
public function actionRenderPageByAjax($view)
{
$params = array(); // Variables to view.
$this->renderPartial('//myFolderView/'.$view, array(
'params' => $params,
), false, true);
}
答案 2 :(得分:1)
在视图中:
<?php Yii::app()->clientScript->registerScript('some-name', "
$('select').on('change', function (event) {
var url = $(event.currentTarget).val();
if (url != 0)
$.get(url, function (data) {
$('#result').html(data);
});
});", CClientScript::POS_READY) ?>
<?php echo
CHtml::dropDownList("param", "select here", [
'Select here',
$this->createUrl('/testing/action1') => "Add class teacher",
$this->createUrl('/testing/action2') => "Add class techer"
]) ?>
<div id="result"></div>