简体   繁体   English

jQuery Chosen插件-手动选择选项

[英]jQuery Chosen plugin - select option manually

I've been trying to select some options manually in the Chosen plugin. 我一直在尝试在“选择”插件中手动选择一些选项。

Why i need something like that? 为什么我需要这样的东西?

My concept is :Let's say a user wants to put some tags to a video,when he inserts the video to the database the tags will be saved in a database too. 我的概念是:假设用户想在视频中添加一些标签,当他将视频插入数据库时​​,标签也将保存在数据库中。 When he wants to edit this video i have to query these tags from the database and show them to the user so he can edit/delete/add new. 当他想要编辑此视频时,我必须从数据库中查询这些标签并将其显示给用户,以便他可以编辑/删除/添加新标签。

My question: 我的问题:

Is there any way to put these tags in an array and then put them as an already selection? 有什么方法可以将这些标签放入数组,然后将其作为已经选择的标签?

Just add the selected property when you get the existing tags from the database. 从数据库中获取现有标签时,只需添加selected属性。 Let us say a video is tagged with a and b , so when you show the select list it would look like this: 假设视频用ab标记,那么当您显示select列表时,它看起来像这样:

<select id="assets" data-placeholder="Choose assets" class="chzn-select" multiple style="width:350px;">
    <option value="a" selected>a</option>
    <option value="b" selected>b</option>
    <option value="c">c</option>
    <option value="d">d</option>
    <option value="e">e</option>
    <option value="f">f</option>
    <option value="g">g</option>
</select>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM