typehead ajax format relay

异步搜刮提醒的完成

/**
 * 异步搜刮
 * @type {Bloodhound}
 */
var bestPictures = new Bloodhound({
    datumTokenizer: Bloodhound.tokenizers.obj.whitespace('data'),
    queryTokenizer: Bloodhound.tokenizers.whitespace,
    remote: {
        url: GUI.data.API.searchUser,
        rateLimitWait: 700,
        prepare: function(query, settings) {
            console.log(query);
            settings.type = "POST";
            settings.contentType = "application/x-www-form-urlencoded; charset=UTF-8";
            settings.data = {
                keyName: query
            };

            return settings;
        },
        transform: function(response){
          console.log(response);
          return response.data
        }
    }
});

$('#the-basics .typeahead').typeahead(null, {
    name: 'best-pictures',
    limit: '11',
    display: 'data',
    source: bestPictures,
    templates: {
      empty: [
          '<div class="empty-message">',
            '没有查询到相干的纪录',
          '</div>'
        ].join('\n'),
      suggestion: Handlebars.compile('<div class="result-item">{{name}} <span class="small">{{deptName}}</span></div>')
    }
});
    原文作者:Guoye
    原文地址: https://segmentfault.com/a/1190000019003075
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞