我使用http://demos.krajee.com/widget-details/select2#usage-tags 控制器
public function actionTagsForm()
{
$method = Yii::$app->request->isAjax ? 'renderAjax' : 'render';
$model = new UserTagsForm();
return $this->$method('tagsForm', ['model' => $model]);
}
views / layouts / main.php有代码模式窗口
<?php
yii\bootstrap\Modal::begin([
'header' => '<div id="modalHeader"></div>',
'id' => 'modal',
'size' => 'modal-lg',
'options' => [
'tabindex' => false
],
]);
echo "<div id='modalContent'></div>";
yii\bootstrap\Modal::end();
?>
视图
$data = [
"red" => "red",
"green" => "green",
"blue" => "blue",
"orange" => "orange",
"white" => "white",
"black" => "black",
"purple" => "purple",
"cyan" => "cyan",
"teal" => "teal"
]; ?>
<div class="image-tags-index">
<?php $form = ActiveForm::begin();?>
<?php echo $form->field($model, 'image_tags')->widget( Select2::classname(),[
'data' => $data,
'options' => ['placeholder' => 'Select a state ...'],
'pluginOptions' => [
'allowClear' => true
],
])->label('Tag Multiple');
?>
</div>
错误
VM314:2未捕获的ReferenceError:未定义select2_3f25e3ac at eval(eval at globalEval(jquery.js:343),:2:56) 在eval() 在Function.globalEval(jquery.js:343) 在domManip(jquery.js:5291) 在jQuery.fn.init.append(jquery.js:5431) 在jQuery.fn.init。 (的jquery.js:5525) 在访问(jquery.js:3614) 在jQuery.fn.init.html(jquery.js:5492) 在对象。 (的jquery.js:9436) 在火上(jquery.js:3187)