Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

92
Visualizações
For each object Javascript

hope all is fine for you I'm a beginner in javascript and i'm trying to integrate a video customer review API on my website. The integration is working on all my pages but on one product page i'd like to init the sdk for each videos id returned by the object to display all the video reviews of this product.

The sdk returned an object as below : enter image description here

And i have to display the sdk like that :

 SDK.init(
            {
                type: "player",
                args: {
                    key: playerKey,
                    id: videoId, // Id returned by the object on the screenshot
                    width: '100%',
                    height: "inherit",
                },
            },
            videoPlayer //=> my div element 
        )

i tried the for each method, objects as below but nothing work for me, each time only 1 player is displaying.

 Object.keys(videos).forEach(id => {
        console.log(videos); 
        SDK.init(
            {
                type: "player",
                args: {
                    key: playerKey,
                    id: videoId,
                    width: '100%',
                    height: "inherit",
                },
            },
            videoPlayer
        )
      });

I have no archive what i tried before this but i'm a little bit lost

Have a nice day and thank you

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

The documentation indicates that one HTML element should be dedicated to one player. So you cannot put several players in one element.

You could create child elements inside your container element.

Assuming that videos is an array, like depicted in the screenshot:

videos = [
    { id: '....' },
    { id: '....' }
]

then do this:

for (let {id} of videos) {
    console.log("video ID", id);
    const wrapper = document.createElement("div");
    videoPlayer.appendChild(wrapper);
    SDK.init(
        {
            type: "player",
            args: {
                key: playerKey,
                id,
                /* any other properties you want to add here */
            },
        },
        wrapper
    );
}
about 4 years ago · Juan Pablo Isaza Relatório

0

I didn't try the SDK, but as @T.J. Crowder mentioned in the comment you probably need to create new <div> for every init call, something like this:

 Object.keys(videos).forEach(id => {
        console.log(videos); 
        const node = document.createElement("div");
        node.style.width = '500px';
        node.style.height = '500px';
    
        videoPlayer.appendChild(node)

        SDK.init({
            type: "player",
            args: {
                key: playerKey,
                id: videoId,
                width: '100%',
                height: "inherit",
            },
        }, node)
      });
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda