JQRelcopy无法在renderPartial()中工作

时间:2015-09-07 11:51:59

标签: php jquery yii yii-extensions

我在弹出视图中使用了JQRelcopy扩展。当我使用render()时,扩展工作正常但每次打开颜色框时都会将旧值POST给控制器。 如果我使用renderPartial(),它会在我打开颜色框时每次向控制器发布新值,但扩展名(JQRelcopy)不会克隆字段。

这是我在视图中使用extenion的地方:

Yii::import('ext.jqrelcopy.JQRelcopy');

$this->widget('ext.jqrelcopy.JQRelcopy',array(
    'id' => 'copylink',
    'removeText' => '<i class="icon-remove" style="margin-left: 1px;"></i>',
    'removeHtmlOptions' => array('style'=>'color:red; margin-left: 45px'),
    'jsAfterCloneComplete' => 'initializeTimePicker()',
    'jsAfterNewId' => JQRelcopy::afterNewIdDatePicker(Util::getCustomDatePicker($briefingEquipment, 0, $minDate, $maxDate)),

    'options' => array(
        'copyClass' => 'copy',
        'limit' => 10,
        'clearInputs' => true,
        'excludeSelector' => '.skipcopy',
    )
));

这是我的控制器代码:

public function actionShowEquipment()
{
    $this->layout = "//layouts/popup";

    $equipmentConflicts = '';
    $briefingId = $_POST['briefingId'];
    $briefingDate = $_POST['briefingDate'];
    $briefingEndDate = isset($_POST['briefingEndDate']) ? $_POST['briefingEndDate'] : '';
    $serializeBriefingEquipments = isset($_POST['briefingEquipments']) ? $_POST['briefingEquipments'] : '';

    $equipment = CHtml::listData(Equipment::model()->findAll(), 'id', 'name');
    $briefingCenter = BriefingCenter::model()->findByPk(Yii::app()->user->currentBriefingCenterId);

    if ($briefingId) {
     $briefingEquipmentArr = BriefingEquipment::model()->findAll('briefing_id = :bId', array(':bId' => $briefingId));

        if (!$briefingEquipmentArr) {
            $briefingEquipmentArr[] = new BriefingEquipment();
        }
    } else if ($serializeBriefingEquipments) {
        $serializeBriefingEquipments = unserialize($serializeBriefingEquipments);
    }

    $briefing = Briefing::model()->findByPk($briefingId);

    if (!empty($briefing->scheduled_date) && !empty($briefing->scheduled_end_date)) {
        $minDate = $briefing->scheduled_date;
        $maxDate = $briefing->scheduled_end_date;
    } else {
        $minDate = $briefingDate;
        $maxDate = $briefingEndDate;
    }

    echo $this->renderPartial('edit/equipment', array(
        'briefing' => array(
            'briefingId' => $briefingId,
            'briefingDate' => $briefingDate,
            'briefingEndDate' => $briefingEndDate,
        ),
        'minDate' => strtotime($minDate),
        'maxDate' =>  strtotime($maxDate),
        'briefingEquipmentArr' => $briefingEquipmentArr,
        'equipments' => $equipment,
        'briefingCenter' => $briefingCenter,
        'serializeBriefingEquipments' => $serializeBriefingEquipments,
        'dateFormat' => Yii::app()->user->currentBriefingCenterDateFormat,
    ));
}

1 个答案:

答案 0 :(得分:0)

问题是因为render和renderPartial,我使用了render并且扩展工作完全正常。 以下是我从Stackoverflow中获取的render和renderPartial之间的区别。

render()通常用于呈现与用户看到的&#34;页面相对应的视图。在你的申请中。它首先渲染您指定的视图,然后渲染当前控制器操作的布局(如果适用),将第一个渲染的结果放入布局中。然后执行输出处理(此时意味着自动插入任何必要的标签并更新动态内容),最后输出结果。

renderPartial()通常用于渲染&#34;&#34;一页与render()的主要区别在于此方法不会将渲染的结果放在布局中。默认情况下,它也不执行输出处理,但您可以使用$ processOutput参数覆盖此行为。