[英]How to use fieldset in lightning Component
I want to create a custom lightning component to create new Case records and need to use fieldset to include fields in component.我想创建一个自定义闪电组件来创建新的案例记录,并且需要使用 fieldset 在组件中包含字段。 Need to use this only for one object.只需要对一个 object 使用它。 I never used fieldsets so dont have any idea on it.我从未使用过字段集,所以对此一无所知。 It would be really great if you can share some sample code or any link for the same.如果您可以共享一些示例代码或任何相同的链接,那就太好了。
You can use this utility class您可以使用此实用程序 class
This is the wrapper class to hold the meta info about the fields这是包装器 class 保存有关字段的元信息
public with sharing class DataTableColumns {
@AuraEnabled
public String label {get;set;}
@AuraEnabled
public String fieldName {get;set;}
@AuraEnabled
public String type {get;set;}
public DataTableColumns(String label, String fieldName, String type){
this.label = label;
this.fieldName = fieldName;
this.type = type;
}
}
Class FieldSetHelper has a method getColumns () this will return the list of DataTableColumns wrapper containing the information about the filedset columns Class FieldSetHelper 有一个方法 getColumns () 这将返回包含有关字段集列信息的 DataTableColumns 包装器列表
public with sharing class FieldSetHelper {
/*
@param String strObjectName : required. Object name to get the required filed set
@param String strFieldSetName : required. FieldSet name
@return List<DataTableColumns> list of columns in the specified fieldSet
*/
public static List<DataTableColumns> getColumns (String strObjectName, String strFieldSetName) {
Schema.SObjectType SObjectTypeObj = Schema.getGlobalDescribe().get(strObjectName);
Schema.DescribeSObjectResult DescribeSObjectResultObj = SObjectTypeObj.getDescribe();
Schema.FieldSet fieldSetObj = DescribeSObjectResultObj.FieldSets.getMap().get(strFieldSetName);
List<DataTableColumns> lstDataColumns = new List<DataTableColumns>();
for( Schema.FieldSetMember eachFieldSetMember : fieldSetObj.getFields() ){
String dataType =
String.valueOf(eachFieldSetMember.getType()).toLowerCase();
DataTableColumns datacolumns = new DataTableColumns(
String.valueOf(eachFieldSetMember.getLabel()) ,
String.valueOf(eachFieldSetMember.getFieldPath()),
String.valueOf(eachFieldSetMember.getType()).toLowerCase() );
lstDataColumns.add(datacolumns);
}
return lstDataColumns;
}
}
After you getting all those field set information the create lightning component dynamically获得所有这些字段集信息后,动态创建闪电组件
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.