简体   繁体   English

Bootstrap 3和Typeahead,如何将JSON数据放入下拉列表

[英]Bootstrap 3 and Typeahead, how to get JSON data into dropdown

I can't seem to get the JSON results to populate to the input after the data is returned from the server. 从服务器返回数据后,我似乎无法将JSON结果填充到输入中。 This is the post function I am using and it is giving me well a formed JSON string. 这是我正在使用的post函数,它给了我很好的格式JSON字符串。 From what I understand from the docs, the response that is returned is what should be populating to the input, but is not in my case. 根据我对文档的了解,返回的响应应该填充到输入中,但就我而言不是。

$('#employeeSearch').typeahead({
  source:function(query, process) {
    return $.post('employee.asp', {query:query}, function(data) {
      return data;
    }, 'json');
  }
});

Here is the sample string being returned from the server: 这是从服务器返回的示例字符串:

[{"name":"Jody Masters","id":"18"}]

What am I missing here? 我在这里想念什么?

Try this one: 试试这个:

$.post('employee.asp', { query: query }, function(data) {

    $('#employeeSearch').typeahead({
        source: data
    });

}, 'json');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM