【发布时间】:2017-04-13 05:05:47
【问题描述】:
我创建了 select2 下拉菜单。现在我想在这个下拉显示中按国家名称添加描述、城市、商店等。 如何添加国家城市名称、地区、商店等?
(function($) {
$(function() {
var isoCountries = [
{ id: 'QA', text: 'Qatar',},
{ id: 'CA', text: 'Canada'},
{ id: 'CN', text: 'China'},
{ id: 'DE', text: 'Germany'},
{ id: 'RU', text: 'Russia'},
{ id: 'IT', text: 'Italy'}
];
$("[name='market']").select2({
placeholder: "Select a country",
data: isoCountries
});
});
})(jQuery);
【问题讨论】:
-
select2.github.io/examples.html#data-ajax使用该选项编辑select2的查看html:
formatSelection: function(item) { return item.text + ' ' + item.xxx; // Some other property } -
查看示例页面源代码 (Ctrl+U) 以查看 select2 中的 html 中显示的额外数据
标签: jquery jquery-select2 select2