预先输入不显示数组的多个结果

时间:2017-01-05 00:01:23

标签: javascript php typeahead.js bloodhound

您好我在搜索结果中生成以下数组:

[{"id":"292","clientname":"John Mick"},{"id":"293","clientname":"John Tom"}]

这是从MySQL Query返回的内容,但在我的Twitter类型配置中没有显示任何内容。而不是显示2结果。

这是我的先行代码:

<script type="text/javascript">
$(function() {
  // Instantiate the Bloodhound suggestion engine
  var curr = {};
  var suggestions = new Bloodhound({
    datumTokenizer: function(datum) {
      return Bloodhound.tokenizers.whitespace(datum.value);
    },
    queryTokenizer: Bloodhound.tokenizers.whitespace,
    remote: {
        url: 'includes/livesearch.php?key=%QUERY',       
        wildcard: '%QUERY',
        filter: function (clientname) {
          curr[clientname.clientname] = clientname.id;
            // Map the remote source JSON array to a JavaScript object array
            return $.map(clientname, function (clientname, index) {
                return index === "clientname" ? {
                    value: clientname
                } : null;
            });
        }
    }

  });
  // Initialize the Bloodhound suggestion engine
  suggestions.initialize();

  // Instantiate the Typeahead UI
  $(".typeahead").typeahead({
    hint: true,
    minLength: 1
  }, {
    limit: 7,
    displayKey: 'value',
    source: suggestions.ttAdapter(),

  })
  .on("typeahead:selected", function (e, datum) {
    $("form [name=clientid]").val(curr[datum.value]); // set value here
    curr = {};
    var value = document.getElementById("clientid").value;
    if (value == 292) {
        $("#alltask").hide();
        $("#singletask").show();
    } else {
        $("#singletask").hide();
        $("#alltask").show();
    }
  });
})
</script> 

欢迎任何有助于解决这一困难局面的帮助。谢谢!

0 个答案:

没有答案