Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript JQuery:为什么我得到一个未捕获的类型错误:无法设置属性'_renderItem';未定义的_Javascript_Jquery_Autocomplete_Dreamfactory - Fatal编程技术网

Javascript JQuery:为什么我得到一个未捕获的类型错误:无法设置属性'_renderItem';未定义的

Javascript 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

这段代码应该获取一个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/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显示相关标记