Skip to content

Issue with Dynamically Loading JSON Data in View Files #1480

Closed Answered by arkdev1
arkdev1 asked this question in Q&A
Discussion options

You must be logged in to vote

No, you can do something like this: x-data "formatJson" and use the $ref of the alpine element, for example. But I'm not sure 😁

My stupidity.
With AlpineJs all is resolved, thanks @luanfreitasdev

<div class="p-2 bg-white border border-slate-200">
    <div x-data="window.jsonFormatter({{$row->id}},'{{($row->json)}}')" class="p-2 bg-white border border-slate-200">
        <div x-ref="container"></div>
    </div>
</div>

in app.js

window.jsonFormatter = function (row_id, json) {
    return {
        init() {
            const rowId = row_id;
            const jsonData = JSON.parse(json);
            const formatter = new JSONFormatter(jsonData);
            this.$refs.container.appendChild(f…

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
2 replies
@arkdev1
Comment options

@luanfreitasdev
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by arkdev1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #1467 on March 27, 2024 16:35.