【问题标题】:Retrieving data while user is typing在用户键入时检索数据
【发布时间】:2017-06-19 04:17:59
【问题描述】:

我的页面中有五个文本字段,当用户在第一个文本字段中键入内容时,我需要根据第一个文本字段检索值。现在,我已将值硬编码为 121,这会从 DB 正确返回值,但如何使其动态化?

<?php echo $form->textField(emp::model()->findByAttributes(array('id' => '121' )),'empno');  ?> 

【问题讨论】:

标签: php yii yii-extensions yii-components


【解决方案1】:

您可以在文本框中键入以下内容时对其进行 ajax 调用:

$("textbox").on('keyup',function(){

    // use get or post request here to retrieve the data
    $.post('url',{parameters},function(data){
        //code to set the data in you UI
    }

});

【讨论】:

    【解决方案2】:

    为此使用 Yii 的内置自动完成小部件。它基于 jQuery UI 库。

    http://www.yiiframework.com/doc/api/1.1/CJuiAutoComplete

    $this->widget('zii.widgets.jui.CJuiAutoComplete',array(
        'name'=>'city',
        'sourceUrl'=> "<your keyword suggestion url here>",
        // additional javascript options for the autocomplete plugin
        'options'=>array(
            'minLength'=>'2',
        ),
    ));
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-01-25
      • 2014-01-02
      • 1970-01-01
      • 1970-01-01
      • 2023-03-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多