通过AJAX调用加载Zii小部件CjuiDatePicker不起作用

Aar*_*ron 2 jquery widget yii

问题总结:
(i)窗体静态部分的小部件工作正常; 但是
(ii)在动态生成的部分中,只显示文本字段(单击它不会创建从中选择日期的日历)

下面的代码显示"动态"尝试:

(1)用户可以点击"(+)日期":

    <?php echo CHtml::link('(+) Date','javascript:void(0);',array('class'=>'date-add'))?>
Run Code Online (Sandbox Code Playgroud)

(2)jquery处理程序执行AJAX请求:

    <script>
        $(".date-add").click(function() { $.ajax({
            success: function(html) {$(".date-list").append(html);}, type: 'get',
            url: '<?php echo $this->createUrl('CreateDate')?>',
            data: {index: counter++}, cache: false, dataType: 'html'
        });});
    </script>
Run Code Online (Sandbox Code Playgroud)

(3)jquery处理程序触发actionCreateDate:

    model = new Date;
    $this->renderPartial('_newDate', array(
        'model' => $model,
    ));
Run Code Online (Sandbox Code Playgroud)

(4)视图代码是

    <?php 
        $this->widget('zii.widgets.jui.CJuiDatePicker', array( 
            'name'=>'Date', 'options'=>array(),'htmlOptions'=>array(),
        ));
    ?>
Run Code Online (Sandbox Code Playgroud)

我该如何解决这个问题(即在动态生成的表单部分中有工作小部件)?提前致谢!

小智 8

您的问题基本上是(3),当您执行渲染部分时,渲染内容的js不会被占用.因此你可以解决这个问题 -

model = new Date;
$this->renderPartial('_newDate', array(
    'model' => $model,
));
Run Code Online (Sandbox Code Playgroud)

作为 -

model = new Date;
$this->renderPartial('_newDate', array(
    'model' => $model,
), false, true);
Run Code Online (Sandbox Code Playgroud)

CController :: renderPartial函数的第四个参数处理渲染内容的js并加载它们.