引导输入错误 [英] Bootstrap typeahead error

查看:35
本文介绍了引导输入错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请帮助我使用 Bootstrap typeahead 解决这个错误.

please help me resolve this error with Bootstrap typeahead.

这是我用来调用源代码的 php 代码.

Here is my php code that I use to call for the source.

    function getUser() {

    $sth = mysql_query("SELECT id,contact FROM cinfo ORDER BY id ASC");
    $rows = array();
    while ($r = mysql_fetch_assoc($sth)) {
        $rows[] = $r;
    }
    print json_encode($rows);
}

这是我的 javascript 文件

Here is my javascript file

更新 2 JS

        $('.user').typeahead({
    source : function(typeahead, query) {
        return $.post('/ticket/getUser', {
            query : query,
        }, function(data) {
            return typeahead.process(data);
        })
    },
    property : 'contact'
}); 

我现在产生以下错误https://gist.github.com/1866577#gistcomment-263183

我正在使用以下引导程序提前输入脚本https://gist.github.com/1866577

I am using the following bootstrap typeahead script https://gist.github.com/1866577

谢谢.

推荐答案

你想显示 contact 而不是 cinfo,因为 cinfo 是表名

You want to display contact not cinfo, because cinfo is the table name

$('.user').typeahead({
 source: '/ticket/getUser',
display:'contact',
id: 'id'
});

更新:

您似乎想使用属性"选项:

Looks like you want to use the 'property' option:

$('.user').typeahead({
 source: '/ticket/getUser',
property:'contact'
});

更新2:

我认为您需要先处理返回数据.试试这个:

I think you need to process the return data first. Try this:

$('.user').typeahead({
    source: function (typeahead, query) 
    {
        return $.post('/ticket/getUser', { query: query }, function (data) 
        {
            return typeahead.process(data);
        });
    },
    property:'contact'
});

这篇关于引导输入错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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