简体   繁体   English

呼叫同一雷电组件内部的雷电组件

[英]Call lightning component inside same lightning component

I'm trying to achieve a lightning component that recursively calls itself to generate a tree hierarchy with attributtes of a filled map that goes like Map<Integer,Map<Id,List<Object>>> being first key the level of the tree and second key the parentid of the list of objects retrieved . 我正在尝试实现一个闪电组件,该组件递归调用自身以生成具有填充地图属性的树层次结构,该属性类似于Map<Integer,Map<Id,List<Object>>>树级别和第二个键是检索到的对象列表的父对象

My question is: Is it possible to create a component that works like this example? 我的问题是: 是否可以创建一个类似于此示例的组件?

CustomLightningComponent CustomLightningComponent

<aura:component>
    <aura:attribute name="mapObject" type="map"/>
    <aura:attribute name="level" type="integer"/>
    <aura:attribute name="parentId" type="string"/>
    <aura:attribute name="listObject" type="list"/>

    <aura:iteration items="listObject" var="obj">
        <p>{!obj.Name}</p>
        <c:CustomLightningComponent mapObject="{!mapObject}" level="{!v.level}" parentId="{!obj.Id}"/>
    </aura:iteration>
</aura:component>

CustomLightningComponentController CustomLightningComponentController

({
    doInit: function(component, event, helper) {
         var map = component.get("v.mapObject");
         var level = component.get("v.level");
         var parentId = component.get("v.parentId");

         var listObjects = map[level][parentId];
         //To iterate over next level
         component.set("v.level", level++);
         //Set list
         component.set("v.listObject", listObjects);
    }
})

The code is pretty basic just to put an example of what I want to implement. 该代码非常基本,仅举一个我想实现的示例。

Is this even possible? 这有可能吗? Call the same lightning component recursively? 递归调用相同的闪电组件?

Yes, It's possible to iterate over child component using aura:iteration tag. 是的,可以使用aura:iteration标签遍历子组件。 However, the map you have created looks very complex and lightning doesn't provide very easy access to map and its contents. 但是,您创建的地图看起来非常复杂,并且闪电无法轻松访问地图及其内容。 Instead of such complex map you can create JSON object in javascript(helper) that will definitely reduce the complexity. 您可以在javascript(helper)中创建JSON对象来代替复杂的地图,这肯定会降低复杂性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM