I have a problem to set the method initSelection with an ajax call, I returns \"undefined\". I checked and the ajax call returns the correct result .. I donot understand the
Pay attention, the data you send to the callback function, needs to be an object, with an id and text attributes.
This is what worked for me:
initSelection: function(element, callback) {
var id;
id = $(element).val();
if (id !== "") {
return $.ajax({
url: url,
type: "POST",
dataType: "json",
data: {
id: id
}
}).done(function(data) {
var results;
results = [];
results.push({
id: data.id,
text: data.name
});
callback(results[0]);
});
}
}