2012-07-08 76 views
2

是否有可能添加一些HTML jQuery自动完成UI项目? 例如,我想将<strong></strong>标记添加到自动填充结果项目label: item['name']。我试过做label: '<strong>'+item['name']+'</strong>,但它是作为文本而不是HTML应用的。如何将自定义HTML添加到jQuery自动完成项目?

$('input[name="customer"]').catcomplete({ 
    delay: 0, 
    source: function(request, response) { 
     $.ajax({ 
      url: 'index.php?route=sale/customer/autocompletefilter_name=' + encodeURIComponent(request.term), 
      dataType: 'json', 
      success: function(json) { 
       response($.map(json, function(item) { 
        return { 
         category: item['customer_group'], 
         label: item['name'], 
         customer : item['name'], 
         value: item['customer_id'], 
         customer_group_id: item['customer_group_id'], 
         firstname: item['firstname'], 
         lastname: item['lastname'], 
         email: item['email'], 
         telephone: item['telephone'], 
         fax: item['fax'], 
         address: item['address'] 
        } 
       })); 
      } 
     }); 
    }, 
    select: function(event, ui) { 
     //some actions on select 
    } 
}); 

Thnak you。

回答

5

查看Scott Gonzales的自动完成HTML扩展 - https://github.com/scottgonzalez/jquery-ui-extensions/blob/master/src/autocomplete/jquery.ui.autocomplete.html.js。它将允许您传递标签选项的HTML。

- http://jsfiddle.net/eay3d/1/

$(function() { 
    var availableTags = [ 
     { label: 'Apple1', value:'Apple1' }, 
     { label: '<strong>Apple2</strong>', value:'Apple2' }, 
     { label: 'Apple3', value:'Apple3' }    
    ]; 
    $("#tags").autocomplete({ 
     source: availableTags, 
     html: 'html' 
    }); 
}); 

编辑2013年9月22日:源链路修复,但不再维持

+0

请注意,此解决方案不适用'.catcomplete' – Kirzilla 2012-07-08 13:58:46

+0

此回购出 – 2013-08-20 18:47:04

相关问题