2015-01-30 4 views
0

Я использую typeahead.js. Я хочу, чтобы эта функция могла производить больше вывода, а не только имя, но также и id. На этот раз я могу отображать только имя. Пожалуйста, помогите мне.bootstrap typeahead имя игорной фамилии и id

var product = new Bloodhound({ 
    datumTokenizer: function (d) { 
     return d.tokens; 
    }, 
    queryTokenizer: Bloodhound.tokenizers.whitespace, 
     remote: { 
      url: "http://localhost/shop/bangunadmin/ajax/get_products", 
      replace: function (url, query) { 
       return url + '#' + query; 
       }, 
      ajax: { 
      type: "POST", 
      data: { 
       q: function() { 
        return $('#product-name3').val(); 
       } 
      } 
      } 
     } 
    }); 
    $("#product-name3").typeahead(null, { 
     name: "product", 
     displayKey: "name", 
     source: product.ttAdapter(), 
     hint: true, 
    }); 
    product.initialize(); 

ответ

0

использовать пользовательские-шаблоны ==>custom-templates

$(input_example).typeahead(null, { 
      name: 'example', 
      displayKey: 'name', 
      source: example.ttAdapter(), 
      //custom your output (in example use Handlebars.js) 
      templates: { 
       suggestion: Handlebars.compile(
        '<div class="text-left" style="color:#222;" data-scode="{{ name }}"><p class="text-left"><strong>{{ id }}</strong></p><div>') 
      } 
     })