Salesforce Lightning组件中的动态可重用自定义列表视图

2023-10-19 07:20

本文主要是介绍Salesforce Lightning组件中的动态可重用自定义列表视图,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

📖摘要


今天分享下 —— Salesforce Lightning组件中的动态可重用自定义列表视图 的一些基本知识,欢迎关注!

Salesforce始终在开发新功能。最近引入了新的闪电组件,称为“ lightning:listView ”。这有助于我们根据特定对象在闪电体验,闪电社区和Salesforce移动应用程序上的列表视图查看所有记录。在标准的“ lightning:listview”组件中,我们一次只能显示一个列表视图,并且要进行更改,我们需要在代码中再次进行编辑。为了使其更加灵活和动态,我们创建了一个自定义下拉菜单,这将帮助我们直接从闪电组件输出更改列表视图。

在这里插入图片描述


❤正题


ListViewController [顶点控制器]
public class listViewController {/*apex method to fetch wrapper of list view*/ @AuraEnabledpublic static list<listViewWrapper> listValues(string objectInfo){list<listViewWrapper> oListViewWrapper = new list<listViewWrapper>();for(ListView lv : [SELECT id, Name, DeveloperName FROM ListViewWHERE sObjectType = : objectInfo ORDER By Name ASC]){ listViewWrapper oWrapper = new listViewWrapper();oWrapper.label = lv.Name;oWrapper.developerName = lv.DeveloperName;oListViewWrapper.add(oWrapper);}return oListViewWrapper; }/*wrapper class to store listView details*/ public class listViewWrapper{@AuraEnabled public string label{get;set;} @AuraEnabled public string developerName{get;set;} }
}

闪电组件[CustomListView.cmp]
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction"access="global"controller="listViewController"><!-- call doInit js function on component load to fetch list view details-->   <aura:handler name="init" value="this" action="{!c.doInit}"/><!-- aura attributes -->   <aura:attribute name="listViewResult" type="string[]"/><aura:attribute name="objectInfo" type="string" default="Account"/><aura:attribute name="currentListViewName" type="string" /><aura:attribute name="bShowListView" type="boolean" default="false"/> <!-- custom dropdown to display available list view options--><div class="slds-form-element"><lightning:select name="select1" onchange="{!c.onPicklistChange}" label=" " class="customCls"><aura:iteration items="{!v.listViewResult}" var="listView"><option value="{!listView.developerName}">{!listView.label}</option></aura:iteration> </lightning:select> </div><!-- lightning List View : https://sforce.co/2Q4sebt--> <aura:if isTrue="{!v.bShowListView}"><lightning:listView objectApiName="{!v.objectInfo}"listName="{!v.currentListViewName}"rows="5"showSearchBar="true"showActionBar="false"enableInlineEdit="true"showRowLevelActions="false"/></aura:if> 
</aura:component>

在此列表视图示例中,我们使用了 Account 对象,您可以根据闪电组件第10行的要求更改对象API(区分大小写)的名称


JavaScript控制器[CustomListViewController.js]
({doInit : function(component, event, helper) {// call apex method to fetch list view dynamically var action = component.get("c.listValues");action.setParams({"objectInfo" : component.get("v.objectInfo")});action.setCallback(this, function(response) {var state = response.getState();if (state === "SUCCESS") {var listViewResult = response.getReturnValue();if(listViewResult.length > 0){// set listViewResult attribute with responsecomponent.set("v.listViewResult",listViewResult);// set first value as default valuecomponent.set("v.currentListViewName", listViewResult[0].developerName);// rendere list view on componentcomponent.set("v.bShowListView", true);     }            } else if (state === "INCOMPLETE") {}else if (state === "ERROR") {var errors = response.getError();if (errors) {if (errors[0] && errors[0].message) {console.log("Error message: " + errors[0].message);}} else {console.log("Unknown error");}}});$A.enqueueAction(action);},onPicklistChange: function(component, event, helper) {// unrenders listView component.set("v.bShowListView", false); // get current selected listview Name var lstViewName = event.getSource().get("v.value"); // set new listName for listViewcomponent.set("v.currentListViewName", lstViewName);// rendere list view again with new listNew  component.set("v.bShowListView", true); },
})
  • 注意:检查代码注释。

CSS [CustomListView.css]
/* align picklist inside list view*/
.THIS .customCls{margin-top: -10px;width: 50%;position: absolute;right: 17px;
}

效果:

在这里插入图片描述


🎉最后

  • 更多参考精彩博文请看这里:《salesforce 系列》

  • 喜欢博主的小伙伴可以加个关注、点个赞哦,持续更新嘿嘿!

这篇关于Salesforce Lightning组件中的动态可重用自定义列表视图的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/238261

相关文章

如何自定义一个log适配器starter

《如何自定义一个log适配器starter》:本文主要介绍如何自定义一个log适配器starter的问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录需求Starter 项目目录结构pom.XML 配置LogInitializer实现MDCInterceptor

Java调用C#动态库的三种方法详解

《Java调用C#动态库的三种方法详解》在这个多语言编程的时代,Java和C#就像两位才华横溢的舞者,各自在不同的舞台上展现着独特的魅力,然而,当它们携手合作时,又会碰撞出怎样绚丽的火花呢?今天,我们... 目录方法1:C++/CLI搭建桥梁——Java ↔ C# 的“翻译官”步骤1:创建C#类库(.NET

Spring组件实例化扩展点之InstantiationAwareBeanPostProcessor使用场景解析

《Spring组件实例化扩展点之InstantiationAwareBeanPostProcessor使用场景解析》InstantiationAwareBeanPostProcessor是Spring... 目录一、什么是InstantiationAwareBeanPostProcessor?二、核心方法解

MyBatis编写嵌套子查询的动态SQL实践详解

《MyBatis编写嵌套子查询的动态SQL实践详解》在Java生态中,MyBatis作为一款优秀的ORM框架,广泛应用于数据库操作,本文将深入探讨如何在MyBatis中编写嵌套子查询的动态SQL,并结... 目录一、Myhttp://www.chinasem.cnBATis动态SQL的核心优势1. 灵活性与可

Mybatis嵌套子查询动态SQL编写实践

《Mybatis嵌套子查询动态SQL编写实践》:本文主要介绍Mybatis嵌套子查询动态SQL编写方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录前言一、实体类1、主类2、子类二、Mapper三、XML四、详解总结前言MyBATis的xml文件编写动态SQL

Druid连接池实现自定义数据库密码加解密功能

《Druid连接池实现自定义数据库密码加解密功能》在现代应用开发中,数据安全是至关重要的,本文将介绍如何在​​Druid​​连接池中实现自定义的数据库密码加解密功能,有需要的小伙伴可以参考一下... 目录1. 环境准备2. 密码加密算法的选择3. 自定义 ​​DruidDataSource​​ 的密码解密3

C++ RabbitMq消息队列组件详解

《C++RabbitMq消息队列组件详解》:本文主要介绍C++RabbitMq消息队列组件的相关知识,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧... 目录1. RabbitMq介绍2. 安装RabbitMQ3. 安装 RabbitMQ 的 C++客户端库4. A

spring-gateway filters添加自定义过滤器实现流程分析(可插拔)

《spring-gatewayfilters添加自定义过滤器实现流程分析(可插拔)》:本文主要介绍spring-gatewayfilters添加自定义过滤器实现流程分析(可插拔),本文通过实例图... 目录需求背景需求拆解设计流程及作用域逻辑处理代码逻辑需求背景公司要求,通过公司网络代理访问的请求需要做请

Python中合并列表(list)的六种方法小结

《Python中合并列表(list)的六种方法小结》本文主要介绍了Python中合并列表(list)的六种方法小结,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋... 目录一、直接用 + 合并列表二、用 extend() js方法三、用 zip() 函数交叉合并四、用

SpringBoot实现Kafka动态反序列化的完整代码

《SpringBoot实现Kafka动态反序列化的完整代码》在分布式系统中,Kafka作为高吞吐量的消息队列,常常需要处理来自不同主题(Topic)的异构数据,不同的业务场景可能要求对同一消费者组内的... 目录引言一、问题背景1.1 动态反序列化的需求1.2 常见问题二、动态反序列化的核心方案2.1 ht