这是我的索引文件。
<?php
use yii\helpers\Url;
use yii\helpers\Html;
use yii\bootstrap\Modal;
use kartik\grid\GridView;
use johnitvn\ajaxcrud\CrudAsset;
use johnitvn\ajaxcrud\BulkButtonWidget;
CrudAsset::register($this);
$this->registerJs($this->render('script2.js'), \yii\web\VIEW::POS_READY);
?>
<div class="op-transaction-listing-index">
<div id="ajaxCrudDatatable">
<?=GridView::widget([
'id'=>'crud-datatable2',
'dataProvider' => $listing,
//'filterModel' => $searchModel,
'pjax'=>true,
'columns' => require(__DIR__.'/_columns.php'),
'toolbar'=> [
],
'striped' => true,
'condensed' => true,
'responsive' => true,
'resizableColumns'=>true,
'persistResize'=>true,
'bordered'=> true,
'panel' => [
'type' => 'primary',
'heading' => '<i class="glyphicon glyphicon-list"></i> Op Transaction Listings listing',
])?>
</div>
</div>
<?= Html::a('Create',false,['id'=>'test','class'=>'btn btn-success pull-right'])?>
<?php Modal::begin([
"id"=>"ajaxCrudModal",
"footer"=>"",// always need it for jquery plugin
])?>
<?php Modal::end(); ?>
我所做的是点击表格单元格,它将删除其中的文本并添加select2下拉列表。
$(document).ready(function(){
$('#crud-datatable2-container > table > tbody > tr:nth-child(1) > td:nth-child(2)').on('click',function(){
$(this).text('');
$(this).append('<select name="testing" class="form-control" id="testing"></select>');
$('select#testing').select2();
});
});
然后它继续显示Uncaught TypeError: $(...).select2 is not a function..
这种类型的错误。我里面只有一个脚本。我哪里做错了?