如何动态更改Controller :: create Url()的属性

时间:2014-01-02 17:48:53

标签: jquery yii

$this->widget('zii.widgets.jui.CJuiAutoComplete', array(
        'name'=>'searchlocation',
        'id'=>'searchlocation',
        'value'=>'',
        'source'=>CController::createUrl('/home/findLocation',
            array(
                'cityid' => 'js: $('#hiddenField').val()',
            )
        ),
        'options'=>array(
            'showAnim'=>'fold',         
            'minLength'=>'1',
            'select'=>'js:function( event, ui ) {
                $("#searchlocation").val( ui.item.label );
                $("#hiddenlocationid").val( ui.item.location_id );
                return false;
            }',
        ),
        'htmlOptions'=>array(
            'onfocus' => 'js: this.value = null; 
                $("#searchlocation").val(null);         
                $("#hiddenlocationid").val(null);',
            'class' => 'input-xxlarge search-query',
            'placeholder' => "Your Location",
        ),
    ));

我想访问隐藏字段值并动态分配给cityid

1 个答案:

答案 0 :(得分:0)

您可以在源文档中使用javascript回调的第三个选项.. http://www.yiiframework.com/doc/api/1.1/CJuiAutoComplete#source-detail

'source'=>
    CJavaScriptExpression::code(
        "$.getJSON(
            ".CController::createUrl('/home/findLocation').", 
            {cityid: $('#hiddenField').val()}
            function(data) { return data; }
         )",
    ),

未经测试