我为我的应用程序使用Bootstrap multiselect,在加载页面时,我需要从数据库中检索数据并根据数据预先选择选项。但我无法让它运作
这是多选
$(@el).find('.fields').multiselect
includeSelectAllOption: true,
buttonWidth:'150px',
maxHeight:350,
buttonText: (options) ->
if (options.length == 0)
return "Select Fields"
else
return options.length + ' selected'
这是代码如何选择
_.each data.fields, (dtfield) ->
$(@el).find('.fields option:contains("#{dtfield}")').prop('selected', true) <-- not working
$(@el).find('.fields').multiselect('select', dtfield) <-- not working either
谢谢!
好的,经过几次尝试,这是更新后的代码:
UI:
$(@el).find('.fields').multiselect
buttonWidth:'150px',
maxHeight:350,
selectAllValue: 'all'
buttonText: (options) ->
if (options.length == 0)
return "Select Fields <b class='caret'></b>"
else
return options.length + ' selected <b class="caret"></b>'
选择选项:
selectedFields = (array of fields you want to select)
$(@el).find('.fields').multiselect 'select', selectedFields