"未捕获错误:语法错误,无法识别的表达式:"使用autoComplete(特殊字符?)

时间:2015-07-04 18:00:41

标签: javascript jquery autocomplete

jQuery 1.10.2& jQuery ui core v1.11.4

当我使用自动完成搜索terme时出现这些错误:

  

未捕获错误:语法错误,无法识别的表达式:Lewis,George E.

     

未捕获错误:语法错误,无法识别的表达式:什么?

当我用鼠标导航结果时,我也有很多这样的事情:

  

未捕获的TypeError:无法读取属性'值'未定义的

这是代码:

function agostoAutocomplete(self){

// Recuperation de la page de recherche
var searchUrl = $(self).attr("data-search");
console.log(searchUrl);

//Création d'une fonction pour les catégories
$.widget("custom.catcomplete", $.ui.autocomplete, {
   _renderMenu: function(ul, items) {
       var that = this,
                  currentCategory = "";
       //Verifie si il y a une categorie
       $.each(items, function(index, item) {
            if(item.category){
                if (item.category != currentCategory) {
                   ul.append("<li class='ui-autocomplete-category MEDIA"+item.idrub+"'><h4>"+item.category+"</h4></li>");
                   currentCategory = item.category;
                   //alert(item.category);
               }
               that._renderItemData(ul, item);
            } else {
               that._renderItemData(ul, item);
               //alert('no category works!');
            }
        });
    }
});
//Lancement de la function créée
$(self).catcomplete({
    delay: 100,
    minLength: 1,
    source: searchUrl,
    autoFocus: true,
    response : function(event, ui) {
        // Test si resultat ou pas
        if (ui.content.length === 0) {
             var noResult = { 
             value: "", 
             label: "No results found" 
             };
             ui.content.push(noResult); 
        } else {
        }
    },
    }).data("custom-catcomplete")._renderItem = function( ul, item ) {
        var noresult = $(item.label);
        console.log("label: "+item.label);
        console.log("category:"+item.category);
        console.log("idobject: "+item.idobject);
        console.log("idRub: "+item.idrub);
        console.log("reference: "+item.reference);
        console.log("value: "+item.value);
        console.log("CompositionObject: "+item.compositionobject);
        //var t = item.label.replace('.',"//.");
        if (item.label == 'No results found'){
            return $("<li class='ui-menu-item ui-no-result'><h4>"+item.label+"</h4></li>").appendTo(ul);
        } else {
            if (item.icon){
                return $("<li></li>").data("ui-autocomplete-item", item)
                .append(
                    $("<a class='ui-menu-item autoAjax' data-id-object="+item.id+" data-id-rubrique="+item.idrub+" data-composition-object="+item.compositionobject+"></a>")
                    .append($("<img></img>").attr('src', item.icon))
                    .append( $("<h5>"+item.label+"</h5>")))
                    .appendTo(ul);
            } else {
                return $("<li></li>").data("ui-autocomplete-item", item)
                .append(
                    $("<a class='ui-menu-item autoAjax' data-id-object="+item.id+" data-id-rubrique="+item.idrub+" data-composition-object="+item.compositionobject+"></a>")
                    .append($("<img></img>").attr('src', "/plugins/spipr_agosto/img/nologo.png"))
                    .append($("<h5>"+item.label+"</h5>")))
                    .appendTo(ul);
            }
        }
};

}

对于其他结果,它的工作方式如下:

  

jose,garcia

  罗伯特,胖子

我试图找到它几个小时,但仍然没有机会..有人知道我错在哪里吗?

这里是片段:

&#13;
&#13;
// Initialisation de Autocomplete
function agostoAutocomplete(self){

	// Recuperation de la page de recherche
	
	//Création d'une fonction pour les catégories
	$.widget("custom.catcomplete", $.ui.autocomplete, {
       _renderMenu: function(ul, items) {
           var that = this,
           			  currentCategory = "";
           //Verifie si il y a une categorie
           $.each(items, function(index, item) {
           		if(item.category){
           			if (item.category != currentCategory) {
	                   ul.append("<li class='ui-autocomplete-category MEDIA"+item.idrub+"'><h4>"+item.category+"</h4></li>");
	                   currentCategory = item.category;
	                   //alert(item.category);
	               }
	               that._renderItemData(ul, item);
           		} else {
	               that._renderItemData(ul, item);
	               //alert('no category works!');
	            }
          	});
        }
	});
	//Lancement de la function créée
   var availableTags = [
      { label: "What?", category: "test1" },
      { label: "Lewis, George E.", category: "test2" },
      { label: "antal", category: "" },
      { label: "annhhx10", category: "Products" },
      { label: "annk K12", category: "Products" },
      { label: "annttop C13", category: "Products" },
      { label: "anders andersson", category: "People" },
      { label: "andreas andersson", category: "People" },
      { label: "andreas johnson", category: "People" }
    ];
	$(self).catcomplete({
    	delay: 100,
    	minLength: 1,
    	source: availableTags,
    	autoFocus: true,
        response : function(event, ui) {
            // Test si resultat ou pas
            if (ui.content.length === 0) {
                 var noResult = { 
	             value: "", 
	             label: "No results found" 
		         };
		         ui.content.push(noResult); 
            } else {
            }
        },
		}).data("custom-catcomplete")._renderItem = function( ul, item ) {
			var noresult = $(item.label);
			console.log("label: "+item.label);
			console.log("category:"+item.category);
			console.log("idobject: "+item.idobject);
			console.log("idRub: "+item.idrub);
			console.log("reference: "+item.reference);
			console.log("value: "+item.value);
			console.log("CompositionObject: "+item.compositionobject);
         	//var t = item.label.replace('.',"//.");
			if (item.label == 'No results found'){
				return $("<li class='ui-menu-item ui-no-result'><h4>"+item.label+"</h4></li>").appendTo(ul);
			} else {
			 	if (item.icon){
					return $("<li></li>").data("ui-autocomplete-item", item)
					.append(
						$("<a class='ui-menu-item autoAjax' data-id-object="+item.id+" data-id-rubrique="+item.idrub+" data-composition-object="+item.compositionobject+"></a>")
						.append($("<img></img>").attr('src', item.icon))
						.append( $("<h5>"+item.label+"</h5>")))
						.appendTo(ul);
				} else {
					return $("<li></li>").data("ui-autocomplete-item", item)
					.append(
						$("<a class='ui-menu-item autoAjax' data-id-object="+item.id+" data-id-rubrique="+item.idrub+" data-composition-object="+item.compositionobject+"></a>")
						.append($("<img></img>").attr('src', "/plugins/spipr_agosto/img/nologo.png"))
						.append($("<h5>"+item.label+"</h5>")))
						.appendTo(ul);
				}
			}
	};
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
 <script src="https://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>

<input type="search" data-search="spip.php?page=autocomplete_center" placeholder="Type an artist name" id="recherche_media_resource" class="recherche" onfocus="agostoAutocomplete(this);" >
&#13;
&#13;
&#13;

非常感谢!

1 个答案:

答案 0 :(得分:1)

删除此行:

Resources

我不确定它有什么用,但它会强制错误,因为var noresult = $(item.label); 将在这里用作选择器,但是例如item.labelLewis, George E.不是有效的选择器