【发布时间】:2015-12-04 11:09:10
【问题描述】:
我使用引导程序 3 和 bootstrap-table。我想使用this 示例中的“标记”模式。
当我使用 select2 版本 3.4.4(如在 x-editable 示例中)时,我的 code 可以工作,但是当我想使用最新版本 4.0.0 时,我的 code 没有不工作。
我收到错误消息:
未捕获的错误:没有 select2/compat/inputData
我尝试将 select2.js 替换为 select2.full.js,但在 this 情况下,可编辑框为空。
如何使可编辑单元格与最新版本的 select2 兼容?
html
<table class="table table-striped table-bordered table-hover" cellspacing="0" id="mainTable" data-click-to-select="true" data-show-toggle="true" data-show-columns="true" data-search="true" data-pagination="true">
<thead>
<tr>
<th data-field="name" data-editable="true">Name</th>
<th data-field="stargazers_count" data-editable="true">Stars</th>
<th data-field="forks_count" data-editable="true">Forks</th>
<th data-field="description" data-editable="true">Description</th>
</tr>
</thead>
<tbody>
<tr><td>ala</td><td>ele</td><td class="tag" data-toggle="manual" data-type="select2" data-value="na, an, sd">na,an,sd</td><td>asd</td></tr>
<tr><td>ala</td><td>ele</td><td class="tag">na,an,sd</td><td>asd</td></tr>
<tr><td>ala</td><td>ele</td><td class="tag">na,an,sd</td><td>asd</td></tr>
</tbody>
</table>
javascript
$.fn.editable.defaults.mode = 'inline';
$('table').bootstrapTable({
editable: true
});
console.log($('.tag'));
var tagCells = $('.tag');
$(tagCells).each(function() {
var tags = $( this ).children(":first").html().replace(/ /g,'').split(",");
console.log(tags);
$(this).editable({
select2: {
tags: tags,
tokenSeparators: [",", " "]
}
});
});
$('.tag').click(function(e) {
e.stopPropagation();
e.preventDefault();
$(this).editable('toggle');
});
【问题讨论】:
-
也许这会有所帮助:github.com/select2/select2/issues/3057 在对话的底部,提到 select2 4 不再对
input标签进行操作。如果我理解的话,首先切换编辑(这会将单元格变成input),然后应用select2,它在版本4 中不支持inputs。 -
select2 文档在示例中也有一个
select(select2.github.io/options.html):<select data-tags="true" data-placeholder="Select an option"></select> -
谢谢,你可以把它写成答案,我可以奖励它。
标签: twitter-bootstrap twitter-bootstrap-3 jquery-select2 x-editable bootstrap-table