如果自动完成开始,datatable.js将停止工作 [英] datatable.js stop working if autocomplete starts

查看:50
本文介绍了如果自动完成开始,datatable.js将停止工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了
1)脚本使用datatable.js显示数据

2)自动完成方法

I have written 1) scripts using datatable.js to show data
2) autocomplete method


  1. PortletDraggable.init();

  2. FormFileUpload.init();

  3. EducationalQualification.init();

  4. WorkExperience.init();

  5. Supervisions.init();

  6. Awards.init();

  7. Publication.init();

  1. PortletDraggable.init();
  2. FormFileUpload.init();
  3. EducationalQualification.init();
  4. WorkExperience.init();
  5. Supervisions.init();
  6. Awards.init();
  7. Publication.init();

所有这些都是数据表方法正常工作。但是当我添加jquery.auto-complete.js脚本引用时,这些方法停止工作并且自动完成开始工作。

All these are datatable methods working properly. But when I add jquery.auto-complete.js script reference, these methods stop working and autocomplete start working.

问题出在哪里,请建议。

Where is the problem, please suggest.

<script>

    $('.date-picker').datepicker({
        format: 'mm/dd/yyyy'
    });


    //  var oTable = null;

    jQuery(document).ready(function () {
        App.init();
        PortletDraggable.init();
        FormFileUpload.init();
        EducationalQualification.init();
        WorkExperience.init();
        Supervisions.init();
        Awards.init();
        Publication.init();
    });

        var tmpMem = 0; var tmpAward = 0; var tmpPub = 0;
        // Js For Autocomplete
        $('input[name=SearchUser]').autocomplete({

            source: function (request, response) {
                tmpMem = 0; tmpAward = 0; tmpPub = 0;
                $.ajax({
                    type: 'GET',
                    url: '@Url.Action("SearchUser", "Profile")',
                    data: { FirstName: $("#SearchUser").val() },
                    //  url: "/Profile/SearchUser?FirstName=" + $("#SearchUser").val(),
                    contentType: "application/json; charset=utf-8",
                    //       dataType: "json",
                    beforeSend: function () {
                        // code to show loading image
                        //$(".ui-content").css("opacity", "0.4");
                        //$("#imgLoader").attr("style", "display:block");
                        //var df = document.getElementById('imgLoader');
                        //df.style.position = 'absolute';
                        //var wd = ($(window).width() / 2) - 45;
                        //var hg = ($(window).height() / 2) - 60;
                        //df.style.left = wd + "px";
                        //df.style.top = hg + "px";
                    },
                    complete: function () {
                         //hide loading image
                        $(".ui-content").css("opacity", "1.0");
                        $("#imgLoader").attr("style", "display:none");
                    },
                    success: function (data) {
                           alert(data.data[0].Fname);
                        response($.map(data.data, function (item) {
                            return {
                                Sn: item.Sn, Fname: item.Fname, Mname: item.Uname, Lname: item.Lname, Title: item.Title,
                                Image: item.Image, Organization: item.Organization, JobTitle: item.JobTitle,
                                Awardname: item.Awardname, AwardYear: item.AwardYear, Pubname: item.Pubname, Pubtype: item.Pubtype, TabType: item.TabType
                            }
                        }))
                    }
                })
            },
            select: function (event, ui) {
                //var domainURL = $("#domainurl").val();
                //window.location = domainURL + "/home/NeighborProfile?id=" + ui.item.id;
                // alert(ui.item.Sn);
            }
        }).data("autocomplete")._renderItem = function (ul, item) {
            //     alert(item);="

            if (item.TabType == "member") {
                if (tmpMem == 0) {
                    tmpMem = 1;
                    return $("<li  class='SearchUserLi'></li>").data("item.autocomplete", item).append(

                   "<a href='  ' class='SearchUserLink'>" +
                       "<img  src='" + item.Image + "' alt='" + item.Fname + "' class='SearchUserImg'>" +
                       "<span class='searchUserLight'>" +
                             item.Title + ". " + item.Fname +
                             "<span style=' font-weight: bold;color:black'>" + "  " + item.Organization + "</span>" +
                       "</span>" +
                       "<span style='  font-size : 10px; color: #3B5998;'>" + item.JobTitle + "</span>" +
                   "</a>"
                   ).prepend("<span class='SearchUsercategory'> Members  </span>").appendTo(ul);
                }
                return $("<li   class='SearchUserLi'></li>").data("item.autocomplete", item).append(
                      "<hr class='SearchUserHr'>" +
                    "<a href='  ' class='SearchUserLink'>" +
                        "<img  src='" + item.Image + "' alt='" + item.Fname + "' class='SearchUserImg'>" +
                        "<span class='searchUserLight'>" +
                              item.Title + ". " + item.Fname +
                              "<span style=' font-weight: bold;color:black'>" + "  " + item.Organization + "</span>" +
                        "</span>" +
                        "<span style='  font-size : 10px; color: #3B5998;'>" + item.JobTitle + "</span>" +
                    "</a>"
                    ).appendTo(ul);
            }
            else if (item.TabType == "award") {
                if (tmpAward == 0) {
                    tmpAward = 1;
                    return $("<li style='padding:0px!important;height:80px'></li>").data("item.autocomplete", item).append(

                   "<a href='  ' class='SearchUserLink'>" +
                       "<img  src='" + item.Image + "' alt='" + item.Fname + "' class='SearchUserImg'>" +
                       "<span class='searchUserLight'>" +
                             item.Title + ". " + item.Fname +
                             "<span style=' font-weight: bold;color:black'>" + "  " + item.Organization + "</span>" +
                       "</span>" +
                       "<span style='  font-size : 10px; color: #3B5998;'>" + "  " + item.Awardname + "(" + item.AwardYear + ")" + "</span>" +
                   "</a>"
                   ).prepend("<span class='SearchUsercategory'> Awards  </span>").appendTo(ul)
                }
                return $("<li style='padding:0px!important;height:80px'></li>").data("item.autocomplete", item).append(
                     "<hr class='SearchUserHr'>" +
                    "<a href='  ' class='SearchUserLink'>" +
                        "<img  src='" + item.Image + "' alt='" + item.Fname + "' class='SearchUserImg'>" +
                        "<span class='searchUserLight'>" +
                              item.Title + ". " + item.Fname +
                              "<span style=' font-weight: bold;color:black'>" + "  " + item.Organization + "</span>" +
                        "</span>" +
                        "<span style='  font-size : 10px; color: #3B5998;'>" + "  " + item.Awardname + "(" + item.AwardYear + ")" + "</span>" +
                    "</a>"
                    ).appendTo(ul);

            }
            else if (item.TabType == "publications") {
                if (tmpPub == 0) {
                    tmpPub = 1;
                    return $("<li style='padding:0px!important;height:80px'></li>").data("item.autocomplete", item).append(

                   "<a href='  ' class='SearchUserLink'>" +
                       "<img  src='" + item.Image + "' alt='" + item.Fname + "' class='SearchUserImg'>" +
                       "<span class='searchUserLight'>" +
                             item.Title + ". " + item.Fname +
                             "<span style=' font-weight: bold;color:black'>" + "  " + item.Organization + "</span>" +
                       "</span>" +
                       "<span style='  font-size : 10px; color: #3B5998;'>" + "  " + item.Pubname + "," + item.Pubtype + "</span>" +
                   "</a>"
                   ).prepend("<span class='SearchUsercategory'> Publications  </span>").appendTo(ul)
                }
                return $("<li style='padding:0px!important;height:80px'></li>").data("item.autocomplete", item).append(
                      "<hr class='SearchUserHr'>" +
                    "<a href='  ' class='SearchUserLink'>" +
                        "<img  src='" + item.Image + "' alt='" + item.Fname + "' class='SearchUserImg'>" +
                        "<span class='searchUserLight'>" +
                              item.Title + ". " + item.Fname +
                              "<span style=' font-weight: bold;color:black'>" + "  " + item.Organization + "</span>" +
                        "</span>" +
                        "<span style='  font-size : 10px; color: #3B5998;'>" + "  " + item.Pubname + "," + item.Pubtype + "</span>" +
                    "</a>"
                    ).appendTo(ul);

            }
        };



</script>


推荐答案

只需添加jquery.ui完整的包脚本参考,而不是添加单个自动完成脚本引用。有一个类似的问题,但在添加jquery.ui并删除自动完成脚本后,一切都开始正常工作。希望它有所帮助

Rather than adding a single Autocomplete script reference, simply add jquery.ui complete bundle script reference. I had a similar problem, but after adding jquery.ui and removing autocomplete scripts, everything started to work fine. Hope it helps

这篇关于如果自动完成开始,datatable.js将停止工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆