JQuery Select2 无法 select 选项

JQuery Select2 Can't select option

我对 Select2 有疑问。一切正常,除了我不能 select 任何选项。我正在使用 select2 3.5.3、KnockoutJS、CoffeeScript 和 JQuery。我的 select2 代码:

generateSelect3 =->
    return '<input data-bind="select2: {
        data:{ results: _.available, text: \'text\'},
        minimumInputLength: 3,
        allowClear: true,
        }" class="select2"></select>'

调用所有文件。我正在定制 select2。它正在初始化代码:

generateSelect2 =->
    return $('<div class="subcontainer"><input type="text" class="input- 
        xxlarge" data-bind="select2ex: {url: (_.params && _.params.url || 
        undefined), value: value, text: text, options: _.params}"></div>');

前往 this link。您只需要 link 2 个文件。 Css 在页眉上,Js 在页脚上。

在select2.js后调用个人js文件,select2.js前必须调用jQuery.js

在您的文件中使用以下代码。

$(document).ready(function () {
    $(".category").select2({
        placeholder: 'Category',
        tags: true,
        width: 'resolve'
    });
    $(".sub-category").select2({
        placeholder: 'Sub Category',
        tags: true,
        width: 'resolve'
    });

});

问题已解决:

return $('<div class="subcontainer"><select
        class="input-xxlarge"
        data-bind="options: _.available,
        optionsText: $.ehr.CodedWidget.formatSelectText,
        optionsValue: function(item) { 
        return item && item.value || (item.value == 0 ? item.value + \'\' : \'\') },
        select2ex: {
        value: value,
        }"></select></div>')