我正在使用 select2 下拉控件来显示设施列表,例如设施 A、B、C...等。以及它的位置细节。我正在寻找以下输出,
目前我可以显示“设施名称”,但想从我的 json 对象中显示城市和州。 如何格式化我的结果以将它们显示为上述 html 格式? 到目前为止,这是我的代码。
<input type="hidden" id="ddlFacility" style="width:100%" />
$("#ddlFacility").select2({
placeholder: "Select a Facility",
ajax: {
url: "my url",
dataType: 'json',
type: "GET",
quietMillis: 50,
data: function ( term ) { return { term: term }; },
results: function (data) {
return {
results: $.map(data, function (item) {
return { text: item.FacilityName, id: item.FacilityId }
})
};
}
}
});