Materialize CSS, show images for autocompleted chips

冷暖自知 提交于 2019-12-04 15:11:39

In my case I used the chip.add event to display the image when chip is entered. Basically I had to duplicate the data passed to the autocompleteOptions and used the chip.tag as key to match the correct image.

$('.chips').on('chip.add', function(e, chip){

  var data = {
    'Kyle Robinson': 'dist/images/user-01.jpg',
    'Rebecca Smith': 'dist/images/user-02.jpg',
    'Aaron Lloyd': 'dist/images/user-03.jpg'
  } //same data passed to autocompleteOptions

  var key = chip.tag;
  $(this).children('.chip').append('<img src="' + data[key] + '">');

});

Live example: jsFiddle

Edit: There is no need to duplicate the data, you can get it using:

$('.chips-initial').material_chip('data');

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!