将图像与jQuery AutoComplete集成 [英] Integrating image with jQuery AutoComplete
本文介绍了将图像与jQuery AutoComplete集成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以我正在研究这个项目,我正在使用jQuery自动完成来显示来自mysql数据库的搜索结果。搜索结果是从具有产品图像的数据库中提取的产品名称。
我如何能够显示如下图所示的产品图片?
so I'm working on this project where I'm using jQuery autocomplete to display search results from a mysql database. The search results are product names fetched from a database which has product images as well. How would I be able to display the product images like in the image below ?
这是我的jQuery自动完成页面:
Here's my jQuery auto complete page :
<script>
$( "#birds" ).autocomplete({
source: "search.php",
minLength: 2,
select: function( event, ui ) {
log( ui.item ? "Selected: " + ui.item.value + " aka " + ui.item.label :
"Nothing selected, input was " + this.actor );
window.location.href = './products/' + ui.item.productid;
//window.location.href = 'product_display.php?id=' + ui.item.value;
// document.testForm.action = "pretravel.php?id="+ui.item.value;
//document.testForm.submit();
}
});
});
</script>
search.php
<?php
include 'dbconnector.php';
// Sanitise GET var
if(isset($_GET['term']))
{
$term = mysql_real_escape_string($_GET['term']);
// Add WHERE clause
//$term="Apple";
$query = "SELECT `productid`, `productname` FROM `products` WHERE `productname` LIKE '%".$term."%' ORDER BY `productid`";
$result = mysql_query($query,$db) or die (mysql_error($db));
$id=0;
$return=array();
while($row = mysql_fetch_array($result)){
//array_push($return,array('label'=>$row['productid'],'actor'=>$row['productname']));
//array_push($return,array('value'=>$row['productid'],'label'=>$row['productname']));
//array_push($return,array('actor'=>$row['productname'],'label'=>$row['productid']));
array_push($return,array('productid'=>$row['productid'],'label'=>$row['productname']));
}
header('Content-type: application/json');
echo json_encode($return);
//var_dump($return);
exit(); // AJAX call, we don't want anything carrying on here
}
else
{
header('Location:index');
}
?>
推荐答案
有一种名为 _renderItem
。
There's a method called _renderItem
that you'd want to use.
以下是使用中的小型演示: http:// jsbin.com/cunuxaqe/2/edit
Here's a small demo of it in use: http://jsbin.com/cunuxaqe/2/edit
这篇关于将图像与jQuery AutoComplete集成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文