【问题标题】:Yii2 - Pass ID to another attribute in GridViewYii2 - 将 ID 传递给 GridView 中的另一个属性
【发布时间】:2019-08-03 16:51:12
【问题描述】:

我想将ID 传递给使用 Javascript 的另一列。
这是我的代码:

['class' => 'yii\grid\SerialColumn'],

        'alumni_id', /*I want to pass this value*/
        'tahun_lulus',
        'file_excel',
        [
            'attribute' => 'status',
            'format' => 'raw',
            'value' => function($data){
                return SwitchInput::widget(
                  [
                      'name' => 'status_11',
                      'pluginEvents' => [
                          'switchChange.bootstrapSwitch' => 'function() { 
                                $.ajax({
                                  method: "POST",
                                  url: "'.Url::to(['/alumni/switch', 'id'=>'1']).'",
                                  data: { status_11: this.checked }
                              })
                            }',
                      ],
                      'pluginOptions' => [
                          'size' => 'mini',
                          'onColor' => 'success',
                          'offColor' => 'danger',
                          'onText' => 'Active',
                          'offText' => 'Inactive',
                      ],
                      'value' => !$data->status
                  ]
                );
            }
        ],

我想将属性 alumni_id 传递给那里有 Javascript 的属性 status(到这个 Url::to(['/alumni/switch', 'id'=>'1'])。
我该怎么做?

【问题讨论】:

    标签: javascript php ajax gridview yii


    【解决方案1】:

    你可以通过下面的代码来实现:

    $data->alumni_id
    

    如果你想将id 值作为$data->alumni_id 传递,那么:

    Url::to(['/alumni/switch', 'id'=>$data->alumni_id])
    

    【讨论】:

    • 是的,终于。谢谢
    猜你喜欢
    • 2013-08-14
    • 1970-01-01
    • 2014-04-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多