0
我一直在寻找解决方案来解决以下问题,但是我读过的以前的问题没有取得任何成功的结果。Select2设置多个选定的选项
我有一个JSON编码数组存储在数据库中,例如["2",2,5]
。我需要从阵列中删除第一个值,并使用其余项目从select2中选择多个特定选项。我目前的解决方案显示如下显示的选项对应的剩余数组的第一个值,但不是第二个。有什么建议么?
$("#sltETags").select2({ placeholder: 'Select a Primary Tag', minimumResultsForSearch: 8}).select2('val', [<?php $LstTags = json_decode($row["Tags"]); for($i = 1; $i < count($LstTags); $i++){ if($i != count($LstTags)-1){ echo '"'.$LstTags[$i].'",'; } else { echo '"'.$LstTags[$i].'"'; }} ?>]);
成果
$("#sltETags").select2({ placeholder: 'Select a Primary Tag', minimumResultsForSearch: 8}).select2('val', ["2","5"]);
HTML代码
<select class="form-control select2" multiple="multiple" data-placeholder="Select Secondary Tags" id="sltETags">
<?php
$LstTags = $TagManager->displayTags(0);
for($i = 0; $i < count($LstTags); $i++){
?><option value="<?php echo $LstTags[$i][0]; ?>"><?php echo $LstTags[$i][1]; ?></option><?php
} ?>
</select>