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

相关文章

python中列表应用和扩展性实用详解

《python中列表应用和扩展性实用详解》文章介绍了Python列表的核心特性:有序数据集合,用[]定义,元素类型可不同,支持迭代、循环、切片,可执行增删改查、排序、推导式及嵌套操作,是常用的数据处理... 目录1、列表定义2、格式3、列表是可迭代对象4、列表的常见操作总结1、列表定义是处理一组有序项目的

C++11范围for初始化列表auto decltype详解

《C++11范围for初始化列表autodecltype详解》C++11引入auto类型推导、decltype类型推断、统一列表初始化、范围for循环及智能指针,提升代码简洁性、类型安全与资源管理效... 目录C++11新特性1. 自动类型推导auto1.1 基本语法2. decltype3. 列表初始化3

springboot自定义注解RateLimiter限流注解技术文档详解

《springboot自定义注解RateLimiter限流注解技术文档详解》文章介绍了限流技术的概念、作用及实现方式,通过SpringAOP拦截方法、缓存存储计数器,结合注解、枚举、异常类等核心组件,... 目录什么是限流系统架构核心组件详解1. 限流注解 (@RateLimiter)2. 限流类型枚举 (

go动态限制并发数量的实现示例

《go动态限制并发数量的实现示例》本文主要介绍了Go并发控制方法,通过带缓冲通道和第三方库实现并发数量限制,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面... 目录带有缓冲大小的通道使用第三方库其他控制并发的方法因为go从语言层面支持并发,所以面试百分百会问到

SpringBoot 异常处理/自定义格式校验的问题实例详解

《SpringBoot异常处理/自定义格式校验的问题实例详解》文章探讨SpringBoot中自定义注解校验问题,区分参数级与类级约束触发的异常类型,建议通过@RestControllerAdvice... 目录1. 问题简要描述2. 异常触发1) 参数级别约束2) 类级别约束3. 异常处理1) 字段级别约束

Olingo分析和实践之OData框架核心组件初始化(关键步骤)

《Olingo分析和实践之OData框架核心组件初始化(关键步骤)》ODataSpringBootService通过初始化OData实例和服务元数据,构建框架核心能力与数据模型结构,实现序列化、URI... 目录概述第一步:OData实例创建1.1 OData.newInstance() 详细分析1.1.1

SpringBoot+EasyExcel实现自定义复杂样式导入导出

《SpringBoot+EasyExcel实现自定义复杂样式导入导出》这篇文章主要为大家详细介绍了SpringBoot如何结果EasyExcel实现自定义复杂样式导入导出功能,文中的示例代码讲解详细,... 目录安装处理自定义导出复杂场景1、列不固定,动态列2、动态下拉3、自定义锁定行/列,添加密码4、合并

一文详解SpringBoot中控制器的动态注册与卸载

《一文详解SpringBoot中控制器的动态注册与卸载》在项目开发中,通过动态注册和卸载控制器功能,可以根据业务场景和项目需要实现功能的动态增加、删除,提高系统的灵活性和可扩展性,下面我们就来看看Sp... 目录项目结构1. 创建 Spring Boot 启动类2. 创建一个测试控制器3. 创建动态控制器注

Python中将嵌套列表扁平化的多种实现方法

《Python中将嵌套列表扁平化的多种实现方法》在Python编程中,我们常常会遇到需要将嵌套列表(即列表中包含列表)转换为一个一维的扁平列表的需求,本文将给大家介绍了多种实现这一目标的方法,需要的朋... 目录python中将嵌套列表扁平化的方法技术背景实现步骤1. 使用嵌套列表推导式2. 使用itert

springboot如何通过http动态操作xxl-job任务

《springboot如何通过http动态操作xxl-job任务》:本文主要介绍springboot如何通过http动态操作xxl-job任务的问题,具有很好的参考价值,希望对大家有所帮助,如有错... 目录springboot通过http动态操作xxl-job任务一、maven依赖二、配置文件三、xxl-