【问题标题】:Add tag words from .get in tagging object在标记对象中添加来自 .get 的标记词
【发布时间】: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>&nbsp;&nbsp;&nbsp;<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


    【解决方案1】:

    我在对象标记中找到了一种新方法,而不是在我的 div 中进行追加,我不再遇到问题:

    var motsArray = [];
    
         $(document).ready(function () {
    
                $.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);
                            motsArray = motsString.split(',');
                            console.log(motsArray);
    //////HERE THAT I ADD MY KEYWORDS IN MY TAGS
                            $('.tag').tagging("add", motsArray);
                        }
    
                    });
                });
    
                $(".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
                });
    
            });
    

    【讨论】:

      猜你喜欢
      • 2017-02-17
      • 2013-06-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多