$(gridID).yiiGridView('getChecked',columnID)返回空数组

时间:2016-02-09 14:07:47

标签: javascript jquery yii yii-components yii2-basic-app

我只想存储票据项的ID,当我检查控制台时,我只是得到一个空数组。知道为什么吗?

CCheckBoxColumn上的Yii doc声明:

  

您也可以调用JavaScript函数   $(gridID).yiiGridView('getChecked',columnID)来检索密钥   已检查行的值。

所以我有:

 $this->widget('bootstrap.widgets.BsGridView', array(
    'id' => 'audits-lines-grid',
    'dataProvider' => $auditlines->search($model->audit_id),
    'filter' => $auditlines,
    'selectableRows' => 2,
    'columns' => array(

        array(
        'class' => 'CCheckBoxColumn', 'selectableRows' => 2,
        'id' => 'selected-checkboxes',
        'value' => 'CHtml::tag("span", array("class" => "$data->statusLabel"), "$data->status", "</span>")',
        'name' => 'CHtml::tag("span", array("class" => "$data->statusLabel"), "$data->status", "</span>")',
        ), 
        (some more code here..)

我试图用

获取检查值
<script>
        $(document).on('click','#block-change-location',function(){
            var items = $('#audits-lines-grid').yiiGridView('getChecked', '#selected-checkboxes')
            console.log(items);
        });
</script>

1 个答案:

答案 0 :(得分:1)

使用

$.fn.yiiGridView.getChecked("your-grid-id", "selected-checkboxes");