簡體   English   中英

如何在yii2中使用pjax更新Yii2中的列?

[英]How to use pjax in yii2 to update a column in Yii2?

我想在單擊按鈕后在views / viewfile / index中使用pjax更新數據庫行的狀態。 如何一步一步地在哪個文件中編寫JavaScript代碼以及在哪個文件中從AJAX獲取數據?

 <?php use yii\\widgets\\Pjax; Pjax::begin(); echo GridView::widget([...]); Pjax::end(); ?> 

 <?php use yii\\helpers\\Html; use yii\\grid\\GridView; /* @var $this yii\\web\\View */ /* @var $searchModel app\\models\\LaptopSearch */ /* @var $dataProvider yii\\data\\ActiveDataProvider */ $this->title = 'Laptops'; $this->params['breadcrumbs'][] = $this->title; ?> <div class="laptop-index"> <h1><?= Html::encode($this->title) ?></h1> <?php // echo $this->render('_search', ['model' => $searchModel]); ?> <p> <?= Html::a('Create Laptop', ['create'], ['class' => 'btn btn-success']) ?> </p> <?php \\yii\\widgets\\Pjax::begin('id' => 'rp1'); ?> <?= GridView::widget([ 'dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [ ['class' => 'yii\\grid\\SerialColumn'], 'id', 'network', 'technology', 'sup_id', 'speaker', 'size', [ 'class' => 'yii\\grid\\ActionColumn', 'template' => '{myButton}' , // the default buttons + your custom button 'buttons' => [ 'myButton' => function($url, $model, $key) { // render your custom button return Html::a('تایید'); } ] ], // [ // 'class' => DataColumn::className(), // this line is optional /* 'attribute' => 'name', 'format' => 'text', 'label' => 'Name', ],*/ // 'optical_drive', //'webcam', // 'touchpad', // 'card_reader', // 'ethernet', // 'vga', // 'hdmi', // 'usb3_ports', // 'usb2_ports', // 'usb_type_c', // 'thunderbolt_ports', // 'serial_ports', ['class' => 'yii\\grid\\ActionColumn'], ], ]); ?> <?php \\yii\\widgets\\Pjax::end(); ?> </div> 

如何在數據庫onclick('mybutton')中保存狀態? 應該在哪個文件中為jajax調用jquery?

使用pjax是否有任何特殊原因?

您可以使用$ this-> registerJs在視圖文件中編寫js代碼(“您的js代碼在這里”); 或在單獨的js文件中,然后將其加載到此頁面上。

您將通過控制器/操作中的ajax請求接收到的數據。一旦收到數據,就可以使邏輯起作用並更新數據庫行。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM