JustMap is a javascript library to map JSON objects to views.
This is a simple example to how to use JustMapJS
First of all, you need to create an HTML model, this model will be filled up and returend by JustMapJS
<div id="domModel"> {{ username }} : {{ birthdate }} </div>
- Get the model from the dom
- Call JustMap.map(domModel, jsonObj)
- Add the returned object to your container
let data = {
username: "Med",
birthdate: "23/06/1990",
photos: ["pic1.jpg", "pic2.jpg", "pic3.jpg", "pic4.jpg"]
};
let domModel = document.getElementById("domModel");
let domModelMapped = JustMap.map(domModel, data);
document.body.append(domModelMapped);
Med : 23/06/1990
{{ attribute_name }}
Attribute binding is used to bind element's attributes to values
<input type="text" name="username" [value]="username" />
If statement is used to show/hide an HTML element based on a condition
<div [*if]="username == 'Med'">Some content here</div>
For/loop statement is used iterate over an array
<div [*for]="photos:photo">
<img [src]="photo" />
</div>
<div id="domModel">
<h3> Username : {{ username }}</h3>
<h3> Birthdate : {{ birthdate }}</h3>
<div [*if]="!photos || photos.length == 0" class="alert alert-info">
No photos were found for this user
</div>
<div [*if]="photos && photos.length > 0">
<div [*for]="photos:photo">
<img [src]="photo" />
</div>
</div>
</div>