2015-06-20 84 views
0

它有什麼辦法使'data-confirm' => Please enter the number'不只是確認,但有一些像JS提示,並得到推定值發送給控制器?yii2 Pjax + java腳本提示

<?php \yii\widgets\Pjax::begin(['id' => 'pjax-orders_table','clientOptions' => ['method' => 'POST'], 'enablePushState'=>false]) ?> 
    <?= GridView::widget([ 
     'dataProvider' => $dataProvider, 
     'id'=>'orders_table', 
     'columns' => [ 
      ['class' => 'yii\grid\SerialColumn'], 
      ///some columns 

      [ 
       'class' => 'yii\grid\ActionColumn', 
       'template' => '{update} {delete}{some}', 
       'buttons' => [ 

        'some' => function ($url,$model,$key) { 
         if($model->status=='not confirm') 
         { 
          return Html::a('<span class="glyphicon glyphicon-trash"</span>',['my/some', 'id' => $model->id],[ 
           'title' => Yii::t('yii', 'Delete'), 
           'data-confirm' => Please enter the number', 
           'data-method' => 'post', 

          ]); 
         } 

        }, 
       ], 
      ], 
     ], 
    ]); ?> 
    <?php \yii\widgets\Pjax::end() ?> 

在控制器

public actionSome() 
{ $dataProvider = new ActiveDataProvider(); 
      $dataProvider->query = Orders::find()->all(); 
return $this->render('some',['dataProvider'=>$dataProvider]); 
} 

回答

2

代替Html::a()使用Html::button()其中按鈕的ID = some_item_id然後寫這個JS代碼

$('.buttons_class').click(function(){ 
      var selection; 
      do{ 
       selection = parseInt(window.prompt("Please enter a number from 1 to 100", ""), 10); 
      } 
      while(isNaN(selection)); 
      if(!isNaN(selection)) 
      { 
       $.post("some",{id:45,prompt_value:selection}, function(response) 
       { 
        console.log(response); 
        $.pjax.reload({container:'#pjax-orders_table'}); 
       }); 
      } 
      })