typehead-ajax-format-relay

49次阅读

共计 800 个字符,预计需要花费 2 分钟才能阅读完成。

异步搜索提示的实现

/**
 * 异步搜索
 * @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>')
    }
});

正文完
 0