";未捕获错误:语法错误,无法识别的表达式:"带有autoComplete(特殊字符?)
"Uncaught Error: Syntax error, unrecognized expression:" with autoComplete (special characters?)
jQuery 1.10.2&jQuery ui core v1.11.4
当我使用自动完成功能搜索术语时,我会出现以下错误:
未捕获错误:语法错误,无法识别的表达式:Lewis,George E.
未捕获错误:语法错误,无法识别的表达式:什么?
当我用鼠标导航时,我也有很多这样的结果:
未捕获的类型错误:无法读取未定义的属性"value">
这是代码:
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
或
robert,fatice
我试着找了好几个小时,但还是没有机会。。有人知道我错在哪里吗?
这里的片段:
// 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);
}
}
};
}
<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);" >
非常感谢!
删除此行:
var noresult = $(item.label);
我不确定它有什么好处,但它会导致错误,因为item.label
将在这里用作选择器,但例如Lewis, George E.
或What?
不是有效的选择器
相关文章:
- 铬:“;未捕获的语法错误:意外的标记:"
- 可以设置“;文件名"发生错误时显示的内联脚本标记的
- "未捕获的语法错误:意外的标记}"
- Soundcloud api"未捕获的类型错误:无法读取属性'uri'“未定义”;
- 为什么我会出现此错误"未捕获引用错误:未定义标题;
- "未捕获的语法错误:意外的标记"角度JS
- 内联javascript与"<脚本>"字符串错误地关闭了脚本标记
- jquery validate 1.8.1”;jQuery"是未定义的错误IE8
- 语法错误:"意外的标记<"在Web控制台中
- Backbone.View渲染错误"TypeError:无效'instanceof'操作数e.
- jsTree jQuery:select_node错误:"无法读取属性'obj'“未定义”;
- Parse.com Cloud Code beforeSave()错误:"未捕获尝试用指向新的未保存对象的指针
- MongoDb聚合$match错误:"参数必须是聚合管道运算符“;
- JavaScript运行时错误:“$"未定义-ASP.NET WebForms(MasterPage)
- AngularJS:试图使用一个服务,得到错误"无法读取属性'那么'“未定义”;
- Javascript/HTML”;错误”:"请使用POST请求“;将下拉选择与case/switch语句一起使
- Knockout.js动态选择模板错误:"找不到ID为'的模板'&”;
- 能够创建一个以字符串为键的映射,但当引用该键时;意外的数字错误"
- ReactJS+NodeJS:什么是错误"传递--update binary以重新安装或--build fro
- JSLint错误“是什么;类型错误"意思是