2016-02-09 68 views
0

我只想存儲票據項的ID,當我檢查控制檯時,我只是得到一個空數組。任何想法爲什麼?在CCheckBoxColumn

Yii的文檔指出:

您也可以調用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> 
+0

得到選中的值嘗試'$ .fn.yiiGridView。 getSelection(gridID);'或'var id = $ .fn.yiiGridView.getChecked(「your-grid-id」,「selected-checkboxes」);' –

+0

謝謝瘋狂頭骨,var id = $ .fn.yiiGridView.getChecked(「your-grid-id」,「selected-checkboxes」);工作:) – user83847

回答

1

使用

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