rajasegar / awesome-htmx

Awesome things about htmx
Creative Commons Zero v1.0 Universal
1.87k stars 106 forks source link

add moappi/json2html and htmx #41

Closed ghost closed 1 year ago

ghost commented 1 year ago

intro:

input

<script src="https://cdnjs.cloudflare.com/ajax/libs/json2html/2.1.0/json2html.min.js"></script>

<script>
const button = {'<>':'button', 'class':'button', 'hx-get':'https://pokeapi.co/api/v2/pokemon/ditto',' hx-swap':'outerHTML', text:'Click Me'};
document.write(json2html.render({},button));
</script>

output

output 1: html

<button class="button" hx-get="https://pokeapi.co/api/v2/pokemon/ditto" hx-swap="outerHTML">Click Me</button>

output 2: render-html-in-dom-browser image

output 3: render-html-in-browser image

output 4 image

why?

another idea

<script>
   json2html.component.add("status",{'<>':'span','text':'${status}'});
</script>

<button class="button" hx-get="https://pokeapi.co/api/v2/pokemon/ditto" hx-swap="outerHTML" hx-j2h-componet="status">Click Me</button>
ghost commented 1 year ago

Hi rajasegar, thanks!