I did it using ui:inputSelect on creating lightning component dynamically. Here is the codes:
On controller I put options parameter and fill it datas as in value & label.
var file = component.get("v.file");
component.set("v.fileCreatedByName", file.file.CreatedBy.Name);
var dynamicComponentsByAuraId = {};
for (var i=0; i<file.keyValueMap.length; i++) {
var field = file.keyValueMap[i];
var uiCmp = helper.cmpMap[field.fieldType];
if (field.updateable){
if (field.fieldType == "BOOLEAN")
field.value = field.value == "true";
var cmpAttr = {
"aura:id": field.key,
"label": field.label,
"value": field.value
};
if (field.fieldType == "PICKLIST" || field.fieldType == "MULTIPICKLIST") {
var options = [];
for (var prop in field.options)
options.push({value: prop, label: field.options[prop]});
cmpAttr["options"] = options;
}
if (uiCmp.hasOwnProperty("attributes"))
for (var prop in uiCmp.attributes)
cmpAttr[prop] = uiCmp.attributes[prop];
$A.createComponent(
uiCmp.componentDef,
cmpAttr,
function(newCmp, status, errorMessage){
//Add the new button to the body array
if (status === "SUCCESS") {
var body = component.get("v.body");
body.push(newCmp);
dynamicComponentsByAuraId[newCmp.getLocalId()] = newCmp;
component.set("v.body", body);
}
else if (status === "INCOMPLETE") {
console.log("No response from server or client is offline.")
// Show offline error
}
else if (status === "ERROR") {
console.log("Error: " + errorMessage);
// Show error message
}
}
);
}
}
component.set("v.dynamicComponentsByAuraId", dynamicComponentsByAuraId);
On the Apex side, I pull picklist options as below:
if (field.fieldType == 'PICKLIST' || field.fieldType == 'MULTIPICKLIST'){
Schema.DescribeFieldResult plistDescribe = Schema.getGlobalDescribe().get(config.objectFilePrefix + config.objectFileName).getDescribe().fields.getMap().get(field.fieldId).getDescribe();
List<Schema.PicklistEntry> plistOptions = plistDescribe.getPicklistValues();
Map<String, String> options = new Map<String, String>();
for( Schema.PicklistEntry plo : plistOptions) {
options.put(plo.getValue(), plo.getLabel());
}
keyValueMap.add(new KeyValueMap(field.fieldId, field.fieldLabel, (fieldValue == null) ? '' : fieldValue, !(field.fieldType == 'TEXTAREA' || field.fieldType == 'MULTIPICKLIST'), field.fieldUpdateable, field.fieldType, options));
}
Thats all! It is written for custom objects' custom fields.