AMD / select2 行为差异?
AMD / select2 behavior discrapancy?
我正在尝试修改此处的 select2/AMD 示例: 我不确定我 运行 遇到的问题是否与 select2 有关,或者我是否我误解了AMD。我的代码:
$.fn.select2.amd.define("InlineSearchSelectionCustomAdapter", [
"select2/utils",
"select2/selection/multiple",
"select2/dropdown/search",
],
function (Utils, MultipleSelection, Search) {
let adapter = Utils.Decorate(
MultipleSelection,
Search
);
return adapter;
}
);
$.fn.select2.amd.require([
'select2/selection/multiple',
'select2/selection/search',
'select2/utils',
'InlineSearchSelectionCustomAdapter'
], function (MultipleSelection, Search, Utils, InlineSearchSelectionCustomAdapter) {
let SelectionAdapter = Utils.Decorate(
MultipleSelection,
Search
);
$('.inline-search-original').select2({
selectionAdapter: SelectionAdapter
});
$('.inline-search-amd').select2({
selectionAdapter: InlineSearchSelectionCustomAdapter
});
});
.select2-selection__choice__remove {
display: none !important;
}
.select2-container--focus .select2-autocomplete .select2-selection__choice {
display: none;
}
<link href="//cdnjs.cloudflare.com/ajax/libs/select2/4.0.0/css/select2.css" rel="stylesheet" />
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/select2/4.0.0/js/select2.full.js"></script>
<p>With an inline search box, original</p>
<select style="width: 200px" class="inline-search-original" multiple>
<option value="AL">Alabama</option>
<option value="AK">Alaska</option>
<option value="AZ">Arizona</option>
</select>
<p>With an inline search box, using amd</p>
<select style="width: 200px" class="inline-search-amd" multiple>
<option value="AL">Alabama</option>
<option value="AK">Alaska</option>
<option value="AZ">Arizona</option>
</select>
如您所见,我正在尝试将 SelectionAdapter
重构为一个单独的模块 InlineSearchSelectionCustomAdapter
。但是,我的新 <select>
的外观和行为不同于原始 Whosebug post.
为什么行为不同以及如何更正我的错误?
导入 select2/selection/search
而不是 select2/dropdown/search
$.fn.select2.amd.define("InlineSearchSelectionCustomAdapter", [
"select2/utils",
"select2/selection/multiple",
"select2/selection/search",
],
function (Utils, MultipleSelection, Search) {
let adapter = Utils.Decorate(
MultipleSelection,
Search
);
return adapter;
}
);
$.fn.select2.amd.require([
'select2/selection/multiple',
'select2/selection/search',
'select2/utils',
'InlineSearchSelectionCustomAdapter'
], function (MultipleSelection, Search, Utils, InlineSearchSelectionCustomAdapter) {
let SelectionAdapter = Utils.Decorate(
MultipleSelection,
Search
);
$('.inline-search-original').select2({
selectionAdapter: SelectionAdapter
});
$('.inline-search-amd').select2({
selectionAdapter: InlineSearchSelectionCustomAdapter
});
});
.select2-selection__choice__remove {
display: none !important;
}
.select2-container--focus .select2-autocomplete .select2-selection__choice {
display: none;
}
<link href="//cdnjs.cloudflare.com/ajax/libs/select2/4.0.0/css/select2.css" rel="stylesheet" />
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/select2/4.0.0/js/select2.full.js"></script>
<p>With an inline search box, original</p>
<select style="width: 200px" class="inline-search-original" multiple>
<option value="AL">Alabama</option>
<option value="AK">Alaska</option>
<option value="AZ">Arizona</option>
</select>
<p>With an inline search box, using amd</p>
<select style="width: 200px" class="inline-search-amd" multiple>
<option value="AL">Alabama</option>
<option value="AK">Alaska</option>
<option value="AZ">Arizona</option>
</select>
我正在尝试修改此处的 select2/AMD 示例: 我不确定我 运行 遇到的问题是否与 select2 有关,或者我是否我误解了AMD。我的代码:
$.fn.select2.amd.define("InlineSearchSelectionCustomAdapter", [
"select2/utils",
"select2/selection/multiple",
"select2/dropdown/search",
],
function (Utils, MultipleSelection, Search) {
let adapter = Utils.Decorate(
MultipleSelection,
Search
);
return adapter;
}
);
$.fn.select2.amd.require([
'select2/selection/multiple',
'select2/selection/search',
'select2/utils',
'InlineSearchSelectionCustomAdapter'
], function (MultipleSelection, Search, Utils, InlineSearchSelectionCustomAdapter) {
let SelectionAdapter = Utils.Decorate(
MultipleSelection,
Search
);
$('.inline-search-original').select2({
selectionAdapter: SelectionAdapter
});
$('.inline-search-amd').select2({
selectionAdapter: InlineSearchSelectionCustomAdapter
});
});
.select2-selection__choice__remove {
display: none !important;
}
.select2-container--focus .select2-autocomplete .select2-selection__choice {
display: none;
}
<link href="//cdnjs.cloudflare.com/ajax/libs/select2/4.0.0/css/select2.css" rel="stylesheet" />
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/select2/4.0.0/js/select2.full.js"></script>
<p>With an inline search box, original</p>
<select style="width: 200px" class="inline-search-original" multiple>
<option value="AL">Alabama</option>
<option value="AK">Alaska</option>
<option value="AZ">Arizona</option>
</select>
<p>With an inline search box, using amd</p>
<select style="width: 200px" class="inline-search-amd" multiple>
<option value="AL">Alabama</option>
<option value="AK">Alaska</option>
<option value="AZ">Arizona</option>
</select>
如您所见,我正在尝试将 SelectionAdapter
重构为一个单独的模块 InlineSearchSelectionCustomAdapter
。但是,我的新 <select>
的外观和行为不同于原始 Whosebug post.
为什么行为不同以及如何更正我的错误?
导入 select2/selection/search
而不是 select2/dropdown/search
$.fn.select2.amd.define("InlineSearchSelectionCustomAdapter", [
"select2/utils",
"select2/selection/multiple",
"select2/selection/search",
],
function (Utils, MultipleSelection, Search) {
let adapter = Utils.Decorate(
MultipleSelection,
Search
);
return adapter;
}
);
$.fn.select2.amd.require([
'select2/selection/multiple',
'select2/selection/search',
'select2/utils',
'InlineSearchSelectionCustomAdapter'
], function (MultipleSelection, Search, Utils, InlineSearchSelectionCustomAdapter) {
let SelectionAdapter = Utils.Decorate(
MultipleSelection,
Search
);
$('.inline-search-original').select2({
selectionAdapter: SelectionAdapter
});
$('.inline-search-amd').select2({
selectionAdapter: InlineSearchSelectionCustomAdapter
});
});
.select2-selection__choice__remove {
display: none !important;
}
.select2-container--focus .select2-autocomplete .select2-selection__choice {
display: none;
}
<link href="//cdnjs.cloudflare.com/ajax/libs/select2/4.0.0/css/select2.css" rel="stylesheet" />
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/select2/4.0.0/js/select2.full.js"></script>
<p>With an inline search box, original</p>
<select style="width: 200px" class="inline-search-original" multiple>
<option value="AL">Alabama</option>
<option value="AK">Alaska</option>
<option value="AZ">Arizona</option>
</select>
<p>With an inline search box, using amd</p>
<select style="width: 200px" class="inline-search-amd" multiple>
<option value="AL">Alabama</option>
<option value="AK">Alaska</option>
<option value="AZ">Arizona</option>
</select>