jQuery的:自动完成值和categories.Error:this.source不是一个函数 [英] Jquery:autocomplete values and categories.Error: this.source is not a function

查看:113
本文介绍了jQuery的:自动完成值和categories.Error:this.source不是一个函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是我的Javascript的一部分:

Here is the part of my Javascript:

$(function(){

var dbTags=<?php echo json_encode($namesArray);?>;
var myTag;

$("#searchTags").autocomplete({

  source: dbTags,
  minLength: 2,
  select: function(event, ui){

myTag=ui.item.value;

我的PHP code:

My php code:

$findNames=$user_home->runQuery("SELECT productTitle, category from Iranga ");
$findNames->execute();
$information=$findNames->fetchAll(PDO::FETCH_ASSOC);

foreach($information as $item){

   $namesArray=array("label:"=>$item['productTitle'], "category:"=>$item['category']);

}

我打算使用这个脚本:
https://jqueryui.com/autocomplete/#categories

如何使用和定义我的 dbTags 变量,当它包含产品tilte和类别的问题?

The question how to use and define my dbTags variable, when it contains product tilte and categories?

推荐答案

如果您关注的比如你链接你希望你的来源阵列与标签和类别属性的对象的数组。我不知道你的PHP的输出是什么,或者你正在使用(假设PDO)什么数据库API,但我会尝试:

If you're following the example you linked you want your "source" array to be an array of objects with "label" and "category" properties. I'm not sure what your PHP output is, or what database api you're using (assuming PDO), but I would try:

$findNames=$user_home->runQuery("SELECT productTitle, category from Products");
$findNames->execute();
while ($row=$findNames->fetch()){
 $namesArray[] = array("label" => $row['productTitle'], "category" => $row['category']);
}

这篇关于jQuery的:自动完成值和categories.Error:this.source不是一个函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆