question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Images in nested arrays

See original GitHub issue

Hi, it’s me again. Now I’m having a new trouble wich is that I have a nested array with images inside and when I print the document it just writes [object Object].

My array looks like this: items [ name: 'product 1', description: 'Description for product 1 here....', image: { _type: 'image', source: <source> format: 'image/png', width, height, }, name: 'product 2', description: 'Description for product 2 here....', image: { _type: 'image', source: <source> format: 'image/png', width, height, }, ]

and my docx document looks like this: {#items} {name} {description} {image} {/items}

It prints the name and description correctly, but for the image prints [object Object]

Help!😦

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
alonrbarcommented, Jul 18, 2020

Hi, take your time, no rush here 😃

I’ve checked it now and it does not seem to reproduce. I’ve added this test method to the image.tests.ts file and manually verified the output and everything looks fine. I think cloning the repo and running this test on your machine can help in finding what’s may be wrong.

    it("replaces an image tag in nested loops", async () => {

        const handler = new TemplateHandler();

        const template = readFixture("loop - nested with image.docx");
        const imageFile = readResource("panda1.jpg");

        const imageData = {
            _type: 'image',
            format: MimeType.Jpeg,
            source: imageFile,
            height: 325,
            width: 600
        };
        const itemData = {
            loop_prop2: [
                { simple_prop: imageData }
            ]
        };
        const data = {
            loop_prop1: [itemData]
        };
        for (let i = 0; i < 10; i++) {
            data.loop_prop1.push(itemData);
        }

        const doc = await handler.process(template, data);

        // const docXml = await handler.getXml(doc);
        // expect(docXml).toMatchSnapshot();

        writeTempFile('image - nested loop - output.docx', doc);
    });
1reaction
ayng-98commented, Jul 24, 2020

Sorry!!! My mistake! I was doing something wrong! … It worked! 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Calling and displaying image from a nested array using ...
Hi guys i am having trouble calling and displaying my images that is nested from my JSON array I tried to google it...
Read more >
Work with Image Sequences as Multidimensional Arrays
Function Image Sequence Dimensions Guideline When Used with an Image Sequen... deconvblind m‑by‑n‑by‑p or m‑by‑n‑by‑3‑by‑p PSF argument can be either 1‑D or 2‑D. deconvlucy m‑by‑n‑by‑p...
Read more >
Create an Array of Images in JavaScript (Tutorial)
The best ways to create and use arrays of images in JavaScript. ... You can create nested arrays that store arbitrary metadata such...
Read more >
Array.flat() - for flatting nested arrays within an array
In this third article of the Array method series, I'll explain the flat method and how it works. Here's the video version: Array.flat() ......
Read more >
This week's topic This week's topic is working with 2D ...
The exercises below require you to compose and transform images, represented as 2D arrays using nested loops. Before you start this week's exercise...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found