我正在尝试在我的自定义 joomla 组件中使用 bootstrap select2(ajax),但我没有在返回时列出我的数据。javascript看起来如下
jQuery("#e6").select2({
placeholder: "PLZ // Bundesland // Ort angeben",
minimumInputLength: 2,
ajax: {
url: "index.php?option=com_tieraerzte&task=tieraerzt.locator&tmpl=component",
dataType: 'json',
data: function(term, page) {
return {
q: term, // search term
};
},
results: function(data, page) {
return {results: data};
}
},
formatResult: function(data) {
//shows undefined on return
alert(data.plz);
return "<div class='select2-user-result'>" + data.plz + "</div>";
},
formatSelection: function(data) {
return data.plz;
}
});
返回的 json 数据片段
[[{"plz":"10247","kiez":"Friedrichshain-Kreuzberg","ort":"Berlin","bundesland":"Berlin"}]]