Javascript JQuery:为什么我得到一个未捕获的类型错误:无法设置属性'_renderItem';未定义的
这段代码应该获取一个ISBN或一本书的名称,并在GooglesBookAPI上运行它,返回有效的结果。代码似乎可以独立工作,但当我们将其放入Dreamfactory服务器时,它返回无法将属性“\u renderItem”设置为undefinedJavascript JQuery:为什么我得到一个未捕获的类型错误:无法设置属性'_renderItem';未定义的,javascript,jquery,autocomplete,dreamfactory,Javascript,Jquery,Autocomplete,Dreamfactory,这段代码应该获取一个ISBN或一本书的名称,并在GooglesBookAPI上运行它,返回有效的结果。代码似乎可以独立工作,但当我们将其放入Dreamfactory服务器时,它返回无法将属性“\u renderItem”设置为undefined <script src="https://code.jquery.com/jquery-3.1.1.js"></script> <script src="https://code.jquery.com/ui/1.12.1/j
<script src="https://code.jquery.com/jquery-3.1.1.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
$(function() {
$("#txtBookSearch").autocomplete({
source: function(request, response) {
var booksUrl = "https://www.googleapis.com/books/v1/volumes?printType=books&maxResults=20&q=" + encodeURIComponent(request.term);
$.ajax({
url: booksUrl,
dataType: "jsonp",
success: function(data) {
response($.map(data.items, function(item) {
if (item.volumeInfo.authors && item.volumeInfo.title && item.volumeInfo.industryIdentifiers && item.volumeInfo.publishedDate) {
return {
// label value will be shown in the suggestions
ebook: (item.saleInfo.isEbook == null ? "" : item.saleInfo.isEbook),
title: item.volumeInfo.title,
id: item.id,
author: item.volumeInfo.authors[0],
authors: item.volumeInfo.authors,
isbn: item.volumeInfo.industryIdentifiers,
publishedDate: item.volumeInfo.publishedDate,
image: (item.volumeInfo.imageLinks == null ? "" : item.volumeInfo.imageLinks.thumbnail),
small_image: (item.volumeInfo.imageLinks == null ? "" : item.volumeInfo.imageLinks.smallThumbnail)
};
}
}));
}
});
},
select: function(event, ui) {
location.assign("results.html?id=" + ui.item.id);
},
delay: 600,
minLength: 2,
focus: function(event, ui) {
event.preventDefault();
}
});
$("#txtBookSearch").data("ui-autocomplete")._renderItem = function(ul, item) {
var img = $('<image class="imageClass" src=' + item.small_image + ' alt= n/a' + '/>');
var link = $('<a>' + item.title + ', ' + item.author + ', ' + item.publishedDate + (item.ebook == "" ? "" : ', (Ebook version)') + '</a>');
return $('<li>')
.append("<div>" + img.prop("outerHTML") + link.prop("outerHTML") + "</div>")
.appendTo(ul);
};
});
$(函数(){
$(“#txtBookSearch”).autocomplete({
来源:功能(请求、响应){
var booksUrl=”https://www.googleapis.com/books/v1/volumes?printType=books&maxResults=20&q=“+组件(请求期限);
$.ajax({
url:booksUrl,
数据类型:“jsonp”,
成功:功能(数据){
响应($.map(data.items,函数(item)){
if(item.volumeInfo.authors&&item.volumeInfo.title&&item.volumeInfo.industryIdentifiers&&item.volumeInfo.publishedDate){
返回{
//标签值将显示在建议中
电子书:(item.saleInfo.isEbook==null?“:item.saleInfo.isEbook),
标题:item.volumeInfo.title,
id:item.id,
作者:item.volumeInfo.authors[0],
作者:item.volumeInfo.authors,
isbn:item.volumeInfo.industryIdentifiers,
publishedDate:item.volumeInfo.publishedDate,
图像:(item.volumeInfo.imageLinks==null?”:item.volumeInfo.imageLinks.缩略图),
小图片:(item.volumeInfo.imageLinks==null?”:item.volumeInfo.imageLinks.smallThumbnail)
};
}
}));
}
});
},
选择:功能(事件、用户界面){
location.assign(“results.html?id=“+ui.item.id”);
},
延误:600,
最小长度:2,
焦点:功能(事件、用户界面){
event.preventDefault();
}
});
$(“#txtBookSearch”).data(“ui自动完成”)。_renderItem=函数(ul,项){
var img=$('');
var link=$(''+item.title+'',''+item.author+'',''+item.publishedDate+(item.ebook==''?'':'',(ebook版本)+'';
返回$(“”)
.append(“+img.prop(“outerHTML”)+link.prop(“outerHTML”)+”)
.附录(ul);
};
});
这意味着您没有带有数据用户界面自动完成属性的$(“#txtBookSearch”)
元素。的可能重复项请使用CSST显示相关标记,这意味着您没有$(“#txtBookSearch”)
元素,具有数据ui自动完成
属性。可能重复的请使用css显示相关标记