JSFiddle - React, Tailwind, and code Playground

by Mohammed Ismail Ansari

HTML

<script src="http://ajax.aspnetcdn.com/ajax/knockout/knockout-2.2.1.js"></script>
<div id="people" data-bind="foreach: people">
    <span data-bind="text: firstName + ' ' + lastName"></span>
    <button data-bind="click: $root.selectPerson">Select</button>
    <br />
</div>

CSS

body
{
    font-family: Arial;
}

JavaScript

// Click Binding

// Our viewmodel with observables
function viewmodel() {
    self = this;
    
    this.people = ko.observableArray([
        { firstName: 'John', lastName: 'Shepard' },
        { firstName: 'Kaidan', lastName: 'Alenko' },
        { firstName: 'Ashley', lastName: 'Williams' }]);
    
    this.selectPerson = function(){
        alert("I selected a person");
    };
}

// Runs at document load
$(document).ready(function(){
    // Create an instance of the viewmodel
    var myViewmodel = new viewmodel();
    
    // Bind the instance to the view
    ko.applyBindings(myViewmodel);
});