doudou130216 2017-06-20 11:34 采纳率: 0%
浏览 124

Typeahead:将ajax结果与多个属性匹配

I am using Bootstrap Typeahead (version: v2.0.0). I have result set through an ajax call and would like to show autocomplete list using value and one more attribute.

I have result set like:

{"res":[{"id":617,"value":"DESC: Admin responder comment","user_id":37,"status":1,"comment":"Hi {firstname},

This is testing.","firstname":"Tom's"},
        {"id":625,"value":"DESC: my comment","user_id":37,"status":1,"comment":"Hi {first_name}, anther testing comment","firstname":"William's"}
]}

Autocomplete matching keyword with value attribute and populating it. But, I would like to match keyword with comment attribute as well.

I have tried matcher of typeahead and some solutions mentioned on SO as well but did not found useful. Tried one here: but getting error of "TypeError: Bloodhound is undefined" with that solution.

Please check code below used for autocomplete using result by ajax.

var typeahead_pre_written_xhr = null;
var search_keyword = function ( tid, txtElmt )
{
    $( "#typeahead-input" ).typeahead({
        items: 20,
        source: function(typeahead, query) {

            action_url = _base_url + "search/search_keyword/";
            typeahead_pre_written_xhr = $.ajax({
                cache: false,
                type: "POST",
                dataType: "json",
                url: action_url + query,
                data: { 'type': type },
                error: function (request, status, error) { },
                success: function(data) {    
                    if( typeof data.res != 'undefined' && data.res != '' ) {
                        typeahead.process(data.res);
                    }
                }
            });
        },
        onselect: function() {                  
            // Do stuff
        }
    });
};

Please help me to achieve this.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥30 这是哪个作者做的宝宝起名网站
    • ¥60 版本过低apk如何修改可以兼容新的安卓系统
    • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
    • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
    • ¥50 有数据,怎么用matlab求全要素生产率
    • ¥15 TI的insta-spin例程
    • ¥15 完成下列问题完成下列问题
    • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
    • ¥15 YoloV5 第三方库的版本对照问题
    • ¥15 请完成下列相关问题!