【发布时间】:2021-06-10 15:59:16
【问题描述】:
我将关键字的概念带入带有标签的页面。该页面用作“添加”和“编辑”页面。当它是“修改”时,我将通过 $ .get 查找我的信息。我的问题是它在页面加载时 2 次中的 1 次。
这就是我构建对象标记的方式:
我不深入了解标记对象,所以也许这不是插入标记的方式。
$(document).ready(function () {
$(".tag").tagging({
'no-spacebar': true, // default - false
'forbidden-chars': [".", "_", "?", "#", "×", " "], // double space added
"forbidden-chars-callback": function () {
sweetAlertInput("Vous ne pouvez utiliser ce caractère ", "etabMotsClef");
},
'no-duplicate-callback': function () {
sweetAlertInput("Vous avez déjà utilisé ce mot clé ", "etabMotsClef");
},
'no-duplicate': true,
'no-enter': false,
'tags-limit': 5,
'no-del': true,
'no-quote': true,
'edit-on-delete': false,
'no-comma': true,
'type-zone-class': true,
'no-focus': true,
"tag-on-blur": 0
});
});
得到:
$.get("@Html.Raw(Url.Action("TelechargerInfoOrganisme", "Etablissements"))", function (data) {
//$("#dropdownCFsection").html('<div class="row"><div class= "col-md-6"><div class="form-group"><label for="projectinput5"><strong>@Resource.Organisme</strong></label><select id="organisme" name="organisme" class="custom-select"></select></div></div>');
$.each(data, function (index, row) {
if (row?.etab_motcle) {
var motsString = row?.etab_motcle;
//console.log(motsString);
var motsArray = motsString.split(',');
//console.log(motsArray);
$.each(motsArray, function (index, value) {
$('#etabMotsClef').append(value + ', ');
});
}
});
});
还有html:
<div class="col-md-12">
<div class="form-group">
<label><strong>Liste des mots clés:</strong> <button class="btn btn-info add-special-keys" style="padding-top:3px;padding-bottom:3px;padding-right:6px;padding-left:6px;" type="button"><i class="feather icon-plus"></i></button></label>
<div class="row">
<div class="col-6">
<div class="tag form-control" style="height:120px;outline: none;" data-tags-input-name="tag" maxlength="250" id="etabMotsClef" name="etabMotsClef"></div>
</div>
</div>
</div>
</div>
我使用这个 github 来指导我: https://github.com/sniperwolf/taggingJS#available-options
【问题讨论】:
标签: jquery bootstrap-4 tags tagging