Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Function in function to read JSON #82

Closed
AnastasiaLovelace opened this issue Oct 15, 2020 · 2 comments
Closed

Function in function to read JSON #82

AnastasiaLovelace opened this issue Oct 15, 2020 · 2 comments

Comments

@AnastasiaLovelace
Copy link

Hi,
Abell seams pretty cool but I can't find a way to have a function in an other function to read "complex" JSON

Exemple
I have a JSON file

[
	{
		"title":"Blabla", 
		"tags": ["internet", "ethic"],
		"images":["blabla.png"],
		"date":"août 2019", 
		"sources":{
			"url":"https://github.com/", 
			"description":"Github website"
		}
	}
       {...}
]

And I want to make a .map() in another .map() to add tags and sources information to a page. I try different stuff but it's look like Abell don't want to make that

Is there a way to do it ?

Thanks in advance
Have a nice day 🌞

@saurabhdaware
Copy link
Member

Hi, We have to use ${} inside strings since everything inside double curly brackets is JavaScript

So you can do something like:

{{
  data.map(obj => `
    <b>Tags:</b> 
   ${
        obj.tags
          .map(tag => `<span>${tag}</span>`)
          .join('')
     }
  `)
}}

This should render

<b>Tags:</b>
<span>internet</span><span>ethic</span>

I hope this answers the question. Thank you and have a great day! Let me know if you meant something else

@AnastasiaLovelace
Copy link
Author

AnastasiaLovelace commented Oct 16, 2020

Thanks a lot !
That's what I was looking for !
I think when I tried to do it, the " ` " was missing between ${tag}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants