JSFiddle - React, Tailwind, and code Playground
by kyllle
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js"></script>
<div class="js-output"></div>
<script type="text/html" id="tmpl">
<form action=""></form>
<% _.each(selected, function(model) { %>
<input type="radio" checked><%= model.name %></input><br>
<% }) %>
<% _.each(collection, function(model) { %>
<!-- if model.id doesn't exist in selected and checked then checked?? -->
<% }) %>
<!---->
</form>
</script>
JavaScript
console.clear();
var contact = {
selected: [
{
id: 1,
name: 'Kyle'
},
{
id: 2,
name: 'John'
}
],
collection: [
{
id: 1,
name: 'Kyle',
checked: false
},
{
id: 2,
name: 'John',
checked: false
},
{
id: 3,
name: 'Joe',
checked: true
},
{
id: 4,
name: 'Jane',
checked: false
}
]
};
console.log(contact);
var template = _.template($('#tmpl').html());
$('.js-output').html(template(contact));