i具有以下html,我生成的 <option>
标签是由我生成的(php,更精确地为symfony3)
<select
name="simple_event[tagsList][]"
id="js-tags-list"
class="form-control"
multiple
data-tags="true"
data-placeholder="add-category-separated-by-semicolon"
>
<option selected>html</option>
<option selected>select2</option>
<option selected>jquery</option>
</select>
我将 select2
与lastig片段
$("#js-tags-list").select2({tokenSeparators: [";"]});
我认为这会将3个标签放在预加载数据中,但实际上它只是将它们作为预加载的"建议"(如果我没有放置selected
属性,我认为那是这种情况)
有没有办法执行此操作(即预紧数据),而无需使用我的PHP生成我的JavaScript(这对我来说真的很脏)?
如果从数据库中加载值,Symfony已经提供了预紧数据的东西。http://symfony.com/doc/current/referent/forms/types/entity.html