wychao 2012-06-18 14:56:27 3896次浏览 1条回复 0 0 0

分享,可能有人会和我一样的需求吧。。。。 当然你可能不会用两个CJuiAutoComplete,而是用一个下拉选单。。不过应该还是有参考意义的吧。。。

第一个 CJuiAutoComplete

<?php $this->widget('zii.widgets.jui.CJuiAutoComplete', array(
    'id' => 'area_no2,
    'name' => 'area_no2',
    'value'=>$model->area_no?Area::model()->findByPk($model->area_no)->area_name:"",
    'source' => $this->createUrl('/school/leads/autoArea'),
    'options' => array(
        'delay' => 300,
        'minLength' => 1,
        'showAnim' => 'fold',
        'select' => 'js:function( event, ui ) {
                            $("#'.CHtml::activeId($model, 'area_no').'").val(ui.item.id);
                            $("#'.CHtml::activeId($model, 'city').'").val(ui.item.name);
                        }',
        ),
    'htmlOptions' => array('size' => '30'),
    ));
?>
<?php echo $form->hiddenField($model, 'area_no'); ?>

第二个:

<?php $this->widget('zii.widgets.jui.CJuiAutoComplete', array(
    'id' => 'staff_name',
    'name' => 'staff_name',
    'value'=>is_int($model->staff_id)?Staff::model()->findByPk($model->staff_id)->staff_name:"",
    'source'=>'js: function(request, response) {
        $.ajax({
            url: "'.$this->createUrl('/school/leads/autoStaff').'",
            dataType: "json",
            data: {
                term: request.term,
                brand: $("#'.CHtml::activeId($model, 'area_no').'").val(),
            },
            success: function (data) {
                    response(data);
            }
        })
     }',
    'options' => array(                                                  
        'delay' => 300,
        'minLength' => 1,
        'showAnim' => 'fold',
        'select' => 'js:function( event, ui ) {
                            $("#'.CHtml::activeId($model, 'staff_id').'").val(ui.item.id);
                            return false;
                        }',
        ),
    'htmlOptions' => array('size' => '30'),
    ));
?>
<?php echo $form->hiddenField($model, 'staff_id'); ?>
  • 回复于 2012-06-19 09:34 举报

    好东西,学习了~暂时没有这个需求,以后可能用得着,收藏了~

您需要登录后才可以回复。登录 | 立即注册