1

私はyiiの初心者で、これに問題があり、イライラしました。私はどこでも探していましたが、運がありません。私は以下のグリッドビューを持っています:

$this->widget('bootstrap.widgets.TbGridView',array(
    'id'=>'leaves-grid',
    'template' => "<div>{pager}</div><div style='float:left;'>{summary}</div><div class='clear'>&nbsp;</div>\n{items}\n<div>{pager}</div><div style='float:left;'>{summary}</div><div class='clear'>&nbsp;</div><br/>",
    'dataProvider'=>$model->search(),
    'columns'=>array(
        'id_user',
        'id_leaves_type',
        'leaves_from',
        'leaves_to',
        'leaves_desc',
        'leaves_status',
        array(
            'class'=>'bootstrap.widgets.TbButtonColumn',
            'template' => '<div class="btn-group">{update}{approve}{disapprove}{cancel}</div>',
            'buttons' => array(
            'update' => array(
                'label' => 'Edit',
                'options' => array('class'=>'btn', 'rel' => ''),
                'visible' => '$data->leaves_status == "Pending"'
            ),
            'approve' => array(
                'label' => 'Approve',
                'icon' => 'ok',
                'options' => array('class'=>'btn btn-delete', 'rel' => ''),
                'click'=>'function(){return confirm("Are you sure you would like to approve this leave?");}',
                'url' => 'CController::createUrl("//hrm/leaves/leaveaction", array("id"=>$data->id_leaves, "type"=>"Approved"))',
                'visible' => '$data->leaves_status == "Pending"'
            ),
            'disapprove' => array(
                'label' => 'Disapprove',
                'icon' => 'hand-down',
                'options' => array('class'=>'btn btn-delete', 'rel' => ''),
                'click'=>'function(){return confirm("Are you sure you would like to disapprove this leave?");}',
                'url' => 'CController::createUrl("//hrm/leaves/leaveaction", array("id"=>$data->id_leaves, "type"=>"Not Approved"))',
                'visible' => '$data->leaves_status == "Pending"'
            ),
            'cancel' => array(
                'label' => 'Cancel',
                'icon' => 'remove',
                'options' => array('class'=>'btn btn-delete', 'rel' => ''),
                'click'=>'function(){return confirm("Are you sure you would like to cancel this leave?");}',
                'url' => 'CController::createUrl("//hrm/leaves/leaveaction", array("id"=>$data->id_leaves, "type"=>"Cancelled"))',
                'visible' => '$data->leaves_status == "Pending"'
            ),
            ),
            'htmlOptions'=>array('style'=>'width: 150px; text-align: center;'),
        ),
    ),
));

基本的に、グリッドビューの一番右の列には 4 つのボタンがあります: 編集、承認、非承認、およびキャンセルで、リストされた URL に移動する前に確認ボックスが表示されます。

問題は、ボタンの 1 つをクリックすると、すべてのクリック イベントが発生し、確認ボックスが次々と表示されることです。とにかく間違ったときは何ですか?助けてください...

4

1 に答える 1

1

あなたのコードは次のjsをレンダリングするため

$(document).on('click','#leaves-grid a.btn.btn-delete',function(){return confirm("Are you sure you would like to approve this leave?");});
$(document).on('click','#leaves-grid a.btn.btn-delete',function(){return confirm("Are you sure you would like to disapprove this leave?");});
$(document).on('click','#leaves-grid a.btn.btn-delete',function(){return confirm("Are you sure you would like to cancel this leave?");});

.....

最終クラスを使用してクリックイベントに割り当てると、これらのgeneratdセレクターはすべて同じであることがわかります。それを避けるために、属性クラスの最後に特定のクラスを次のように追加できます

'class'=>'btn btn-approve'
'class'=>'btn btn-disapprove'
'class'=>'btn btn-cancel'
于 2013-08-01T12:40:09.407 に答える