0
我想在views/viewfile/index中使用pjax来点击一个按钮后更新数据库的行状态。如何一步一步地在文件中写入JavaScript代码以及从哪个文件中获取AJAX数据?如何在yii2中使用pjax来更新Yii2中的列?
<?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>
\t <?php \yii\widgets\Pjax::begin('id' => 'rp1'); ?>
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
'id',
'network',
'technology',
'sup_id',
'speaker',
\t \t \t 'size',
\t \t \t [
'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('تایید');
}
]
\t \t \t ],
\t \t \t
\t \t \t // [
// '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'],
],
]); ?>
\t <?php \yii\widgets\Pjax::end(); ?>
</div>
如何保存在数据库状态的onclick( 'myButton的')?哪个文件应该为jQuery调用ajax?
谢谢you.you右边,但有没有关于它的任何复杂的例子 – areff
是的,绝对。对于复杂的js部分,我们更愿意将js写入单独的文件,并将您的应用配置为自动包含与视图名称相同的js文件。这应该处理所有你完整的js和实现将是整洁的 – Gunnrryy
如何为每个按钮设置唯一的ID在一行? – areff