0

I am using Lighting Out and everything is working fine with one instance of my component, but I was hoping to have multiple instances of it on the same page, each with their own attributes. The reason for this is because the page will have an iterated list of cars and a component for each of them, so then I can have the relevant car information for each component. The components always use the attributes from the first component instantiated, however, the DOM locations seem to work out fine:

$Lightning.use("c:tester",
    function () { 
    $Lightning.createComponent(
        "c:carComponent", 
    {
        "car": {
            "year": "2013",
            "make": "BMW",
            "model": "550i"
        }
    }, 
        "lightningLocator1", 
        function (cmp) {
            console.log("Complete 1");
        }
    );
},
    'https://xxxxxxxxx.force.com/cars'
);
$Lightning.use("c:tester", 
    function () { 
    $Lightning.createComponent(
        "c:carComponent",
    {
        "car": {
            "year": "2014",
            "make": "BMW",
            "model": "Z4"
        }
    }, 
        "lightningLocator2", 
        function (cmp) {
            console.log("Complete 2");
        }
    );
},
    'https://xxxxxxxxx.force.com/cars'
);```
  • Why do you want to have multiple instances of the same component with different attributes? Rather, have a single instance and accept as an array of attribute. In this case, array of cars. – Manish Anand Apr 29 at 15:57
  • The page I am trying to put this on has an iterated list of cars, so I was hoping to iterate it along with that list and apply the attributes to each individual component for it is aware of the car it is associated with. I am trying to design it like a widget in a table. – awh01 Apr 29 at 16:16
  • It will increase the load time if the number of cars are large. Also, how are you handling if the number of cars are not known?In this case, it's 2, but will it always be fixed and known? – Manish Anand Apr 29 at 16:30
  • It won't always been known or fixed (think of a pagination data table where you can select the number of results to show). I don't currently have a solution for determining the number of components. I had tried a for loop, but that is when I encountered the issue of the attributes of one component on all components. – awh01 Apr 29 at 16:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.