JSON string data to Array in Edge #1680
Unanswered
gatotsayogya
asked this question in
Help
Replies: 1 comment
-
Can you please format your code blocks properly. Here's the link to the markdown guide https://guides.github.com/features/mastering-markdown/ |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello, I have a controller which passing some data to views
const categories = await Category.all()
const post = await Post.findBy('post_id', params.post_id)
return view.render('backend.edit-post',{
categories: categories.toJSON(),
post: post.toJSON(),
})
in the edge file, I use post.tag(string data wich contains categories_id, eg: 1,2,3) from post(JSON data) to an Array data. I tried to use javascript parse and split in edge but no one works
this is my edge file to checked every cateogry_id in post.tag value
@each(category in categories)<p><label for="{{ category.category_id }}"><input type="checkbox" value="{{ category.category_id }}" name="category_id[]"
@if(in_array(category.category_id, post.tag))checked
@endif>{{ category.title }}</label></p>
@endeach
Beta Was this translation helpful? Give feedback.
All reactions