duanqianhuan3994 2015-03-17 11:37
浏览 73
已采纳

通过js动态添加gridview行中的CJuiAutocomplete

Hi i am trying to create custom widget for my project. The widget includes program name and program type. For field type i have used CJuiAutoComplete. Here is my code!

$this->widget('zii.widgets.grid.CGridView', array(
    'dataProvider' => $this->productArray,
    'id' => 'gridview_add_product',
    'columns' => array(
            array(
                    'header' => 'URL',
                    'value' => 'CHtml::textField("program[$data->id][url]",$data->url,
                    array(
                    \'id\'=>\'program_url_\'.$data->id,
                    ))',
            ),
            array(
                    'header' => 'Type',
                    'value'=>'Yii::app()->controller->widget("zii.widgets.jui.CJuiAutoComplete",array(
                            "name"=>"type",
                            "attribute"=>"resolution",
                            "source"=>array("A","B","C","D","E"),
                            "value"=>$data->type,
                            ),true)',
                    'type' => 'raw',
                    'headerHtmlOptions'=>array('style'=>'width: 100px'),
            ),
            array(
                    'class' => 'CButtonColumn',
                    'headerHtmlOptions'=>array('style'=>'width: 100px'),
                    'buttons' => array(
                            'linkToModel' => array(
                                    'label' => 'Remove',
                                    'click' => "function(){
                                    removeStreamRow($(this));
                                    }",
                            ),
                    ),
            ),
    ),
 ));

Now there is add button which dynamically add new row (name field, type 'autocomplete' and remove button) in CGridView. My js script is as below.

var addProductRow = function(){
$('#gridview_product .empty').parent().remove();
$('#gridview_product tr:last').after('<tr class="odd"><td class="productData"><input id="product_url_'+ nextId + '" type="text" name="product['+ nextId +'][url]"></td><td><input name="type" id="product_'+ nextId + '_type" class = "ui-autocomplete-input" autocomplete = "off" type = "text" ><span class="ui-helper-hidden-accessible" role="status" aria-live="polite"></span></td><td class="button-column"><a class="linkToModel"title="Remove"href="#product_url_'+ nextId + '">Remove</a></td></tr>');nextId--;}

Now when i dynamically add new row through js, the field for "type" do not show AutoComplete functionality.

How could i add CJuiAutocomplete through js in the CGridview row. Please help me out.

  • 写回答

1条回答 默认 最新

  • dtry54612 2015-03-19 09:44
    关注

    After adding html block in gridview you need to bind input field for type with autocomplete event like.

    $( ".ui-autocomplete-input" ).autocomplete({
        source: function(request, response){
         //you source
        }
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 对于这个问题的代码运行
  • ¥50 三种调度算法报错 有实例
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败