简体   繁体   English

如何使用typeahead.js显示图像?

[英]How to display images with typeahead.js?

How to display images with typeahead.js ? 如何使用typeahead.js显示图像?

I am trying to display images for profiles into the list that is created by typehead.js. 我试图将配置文件的图像显示在由typehead.js创建的列表中。

At this moment I can only return texts, as you see there: 在这一刻,我只能返回文本,如你所见:

Here is what my javascript looks like: 这是我的javascript的样子:

And my PHP code, where I construct the profiles list: 我的PHP代码,我构建配置文件列表:

The JSON $json_array_test looks like that: JSON $ json_array_test看起来像这样:

Any idea how to achieve that? 知道如何实现吗?

You can create template for suggestion: 您可以创建建议模板:

$('#search-keywords-page').typeahead({
  hint: true,
  highlight: true,
  minLength: 1
},
{
  name: 'profiles',
  source: profiles,
  templates: {
      suggestion: Handlebars.compile('<div><img src="{{image}}" />{{title}} - {{nid}}</div>')
  }
});

Only return correct json from Your backend: 只从你的后端返回正确的json:

$array_test[$key] = array(
  'title' => $value->title,
  'nid' => $value->nid,
  'image' => $author_image_petite_url
);

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

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