这是haml select2 标记:
= select_tag "v_friend_id",
options_from_collection_for_select(
@v_friends, :id, :full_name, @comparison.v_friend.id
),
:include_blank => true,
:class => "compare-search",
:style => "width:100%; margin-left: 3px;"
这些用户在后端有一个布尔值“isRunning”。我需要用标签'running'(如果isRunning == true)和'citizen'(如果不是真的)创建两个不同的组。
我怎么能用select2做到这一点。无论如何将数据传递回JS并将其推送到数组?那是要走的路吗?
这是我当前的 JS:
$(document).ready(function() {
$('.compare-search').prepend('<option/>').val(function () {
return $(this).val('');
});
$(".compare-search").select2({
placeholder: "Search to compare",
allowClear: true
});
$('.compare-search').on('change', function() {
if (! $(this).val().length) {
$('.vScoreExplain').show();
$('.stats').hide();
}
else {
$('.vScoreExplain').hide();
$('.stats').show();
}
});
});
我希望它看起来像这样,但我指定的类别而不是时区 ^
TLDR:
现在,我可以搜索并选择所有“朋友”,但是,我想根据后端的“isRunning”布尔值将他们分组,类似于我帖子底部的照片如何拆分分成不同时区的组。让我知道这是否没有意义。我可以试着让它听起来更简洁。