xpages - Select2 and JSON Data -
i using select2 version 4 , have rest service control on xpage, reads fullname column names.nsf.
i have search working, reason, don't list of values can select.
the json object being returned, looks this:
[{"@entryid":"1376-e6d5ebe8adbefa7088257df8006e4ba2","fullname":"full name\/ou\/o"},{"@entryid":"1375-fd1cb92a13bfd0e088257de4006756d7","fullname":"another full name\/ou\/o"}]
the code initialize select2 looks this:
x$( "#{id:combobox1}" ).select2({ ajax: { url: "xjson.xsp/names", datatype: 'json', delay: 250, data: function (params) { return { search:'[fullname=]*'+params.term+'*', // q: params.term, // search term page: params.page }; }, results: function (data, page){ }, processresults: function (data, page) { // parse results format expected select2. // since using custom formatting functions not need // alter remote json data console.log(data); return { results: data }; }, cache: true }, //escapemarkup: function (markup) { return markup; }, minimuminputlength: 1 });
when @ browser's console, can see search worked , json objects being returned, however, don't list of values select from.
for result return i've tried results: data.fullname , results: data, text:'fullname' nothing happens.
what doing worng?
you need either switch json response include id
, text
each object, or re-map them in processresults
method. these 2 properties required on selectable objects in select2 4.0. since i'm assuming either can't change json response, or wouldn't make sense to, can re-map data following processresults
method.
processresults: function (data) { var data = $.map(data, function (obj) { obj.id = obj.id || obj["@entityid"]; obj.text = obj.text || obj.fullname; return obj; }); return { results: data }; });
this map @entityid
property id
property , fullname
property text
property. selections sent server containing @entityid
, displayed using fullname
.
also, results
method no longer needed in select2 4.0. renamed current processresults
method.
Comments
Post a Comment