jQuery typeahead的值和名称

时间:2017-05-02 20:34:59

标签: javascript jquery

我正在尝试使用此类型前导代码http://www.runningcoder.org/jquerytypeahead/demo/

但我无法理解这些例子。

服务器响应:

{
  cities: [{
    id: id
    name: name
  },
  {
    id: id2,
    name: name2
  }]
}

这是js

$(function(){
  $.typeahead({
    input: '#hotel-city-autocomplete',
    minLength: 2,
    maxItem: 5,
    order: "asc",
    template: "{{display}} <small style='color:#999;'>{{group}}</small>",
    source: {
      city: {
        ajax: {
          url: '/cities.json',
          path: 'data.cities'
        }
      }
    },
    callback: {
      onResult: function (node, query, result, resultCount) {
      }
    }
  });
});

它不起作用。如何修复它?我想在下拉列表和输入中显示名称并将ID作为值。

0 个答案:

没有答案