我想在弹出窗口中显示我的数据,一旦用户选择部门显示
与使用Ajax,Geeting的用户Selected Department相关的员工姓名
数据的正确但在Eselect2小部件中显示了职员的姓名
Yii中的多个选项,表明Eselect2设计未正常显示
选择下拉菜单用户使用ctrl键选择多项。
我的代码,在该Div员工中,我正在展示eselect2小部件数据。
Ajax编码
<div id ="staffs></div>
function selectstaff(id)
{
$.ajax({
type: 'POST',
url: '<?php echo Yii::app()->createAbsoluteUrl("user/users/ajaxselectstaff"); ?>',
data: 'id=' + id,
success: function (packages) {
$('#staffs').html(packages);
}
});
}
控制器编码
public function actionAjaxselectstaff() {
$id = Yii::app()->request->getPost('id');
$model = Users::model()->getAllStaffDepartment($id);
$this->renderPartial('ajaxselect', array('model' => $model));
}
模式编码
public function getAllStaffDepartment($id, $type = '') {
$model = UserAccount::model()->findAll('department_code=:id', array(':id' => $id));
$userid = "";
$result = "";
if (isset($model)) {
foreach ($model as $data) {
$userid .= $data->user_id . ",";
}
}
$userid = trim($userid, ',');
if ($userid != "") {
$criteria = new CDbCriteria();
$criteria->condition = "user_role_id!=" . Yii::app()->mconstant->CONST_FIVE . " AND user_role_id!= " . Yii::app()->mconstant->CONST_SIX . " AND user_role_id!= " . Yii::app()->mconstant->CONST_NINE . " AND user_id IN (" . $userid . ")";
$result = Users::model()->findAll($criteria);
$data = CHtml::listData($result, 'user_id', 'real_name');
return $data;
} else {
return false;
}
}
Ajaxselect页面:
<?php
Yii::app()->clientScript->scriptMap['jquery.js'] = false;
Yii::app()->clientScript->scriptMap['jquery.min.js'] = false;
if ($model) {
?>
<?php
$this->widget('ext.select2.ESelect2', array(
'name' => 'users',
'id' => 'users',
'data' => $model,
'htmlOptions' => array(
'multiple' => true,
'placeholder' => 'Select Users',
),
));
?>
<?php
} else {
echo "No Staff's Found";
}
?>
我的代码有什么问题?我更改了页面以正确呈现eselect2小部件设计,但未呈现部分eselect2设计,
最佳答案
控制器的细微变化如下所述。
public function actionAjaxselectstaff() {
$id = Yii::app()->request->getPost('id');
$model = Users::model()->getAllStaffDepartment($id);
$this->renderPartial('ajaxselect', array('model' => $model) ,false , true);
}
请在以下链接中找到renderPartial第三和第四参数的描述:http://www.yiiframework.com/doc/api/1.1/CController#renderPartial-detail
关于javascript - Yii renderpartial Eselect2设计不正常,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/36695035/