0

グリッドビュー内のボタンからモーダル ウィンドウにデータを渡そうとしています。モーダル ウィンドウ内でフォームを送信した後に参照できるようにするには、レコードの ID を渡す必要があります。

私はこれにかなり苦労しています。まず、ID 変数をモーダルに渡せるようにする必要があります。次に、送信ボタンをクリックすると、Ajax 呼び出しを実行して DB 内に新しいレコードを作成します。

グリッドビュー

if(isset($results)){
    $this->widget('bootstrap.widgets.TbExtendedGridView', array(
        'id'=>'searchgrid',
        'fixedHeader' => true,
        'headerOffset' => 40, // 40px is the height of the main navigation at bootstrap
        'type'=>'condensed',
        'dataProvider'=>$results,
        'responsiveTable' => true,
        'template'=>"{items}",
        'columns'=>array(
            array('name'=>'title', 'header'=>'Name'),
            array('name'=>'city', 'header'=>'City'),
            array('name'=>'state', 'header'=>'State'),
            array('name'=>'leads', 'header'=>'Leads', 'value'=>'Parkslist::model()->leadRange($data["leads"])'),
            array('name'=>'pastbid', 'header'=>'Previous', 'value'=>'Parkslist::model()->pastBid($data["pasthighbid"])'),
            array('name'=>'currentbid', 'header'=>'Current', 'value'=>'Parkslist::model()->highBid($data["currenthighbid"], $data["secondhighbid"], $data["countcurrenthighbid"])'),
            array('name'=>'minimumbid', 'header'=>'Minimum', 'value'=>'Parkslist::model()->minimumBid($data["currenthighbid"], $data["secondhighbid"], $data["countcurrenthighbid"])'),
            array('name'=>'userhighbid', 'header'=>'Your Bid'),
            array('name'=>'placebid', 'header'=>'Bid', 'value'=>'CHtml::textField("bid" . $data["id"])', 'type'=>'raw'),
            array('name'=>'report', 'header'=>'Report',
                'value'=>function($data){
                    $this->widget('bootstrap.widgets.TbButton', array(
                        'label' => 'Click me',
                        'type' => 'primary',
                        'htmlOptions' => array(
                            'data-toggle' => 'modal',
                            'data-target' => '#myModal',
                            'data-id' => '$data["id"]',
                        ),
                    ));
                }
            ),
        ),
    ));
}

モーダル

<?php
$this->beginWidget('bootstrap.widgets.TbModal', array('id' => 'myModal')); ?>

    <div class="modal-header">
        <a class="close" data-dismiss="modal">&times;</a>
        <h4>Why should this park be removed?</h4>
    </div>
    <form>
    <div class="modal-body">
        <select>
            <option>Duplicate</option>
            <option>Closed</option>
        </select>
    </div>

    <div class="modal-footer">
        <?php $this->widget('bootstrap.widgets.TbButton', array(
        'type' => 'primary',
        'buttonType'=>'submit',
        'label' => 'Save changes',
        'url' => '#',
        'htmlOptions' => array('data-dismiss' => 'modal'),
    )); ?>
        <?php $this->widget('bootstrap.widgets.TbButton', array(
        'label' => 'Close',
        'url' => '#',
        'htmlOptions' => array('data-dismiss' => 'modal'),
    )); ?>
    </div>
    </form>
<?php $this->endWidget(); ?>
4

1 に答える 1

1

これを機能させることができました。もっと良い解決策があるかもしれないと思いますが、これはうまくいくようです。

まず、グリッドビューのボタンの内側で、ボタン ID = をレコードの ID にしました。次に、includeData という JavaScript 関数を作成し、ボタン ID を含めました。

ボタンコード

array('name'=>'report', 'header'=>'Report',
                'value'=>function($data){
                    $this->widget('bootstrap.widgets.TbButton', array(
                        'label' => 'Click me',
                        'type' => 'primary',
                        'htmlOptions' => array(
                            'id'=>$data["id"],
                            'data-toggle' => 'modal',
                            'data-target' => '#myModal',
                            'data-id' => '$data["id"]',
                            'onClick' => 'includeData(this.id);'
                        ),
                    ));
                }
            ),

JS コード

<script type='text/javascript'>
function includeData(parkid){
        $('#reportparkid').val(parkid);

}
</script>

JS 関数は、隠しフィールドの値をボタン ID に設定するだけです。これを処理するためのより良い方法をいくつか見てみたいと思います。

ありがとう

于 2013-08-03T23:03:22.390 に答える