JSFiddle - React, Tailwind, and code Playground
HTML
<input type="text" data-bind="value: title">
<button data-bind="click: create">Add</button>
<ul data-bind="foreach: todos">
<li>
<span data-bind="text: title"> </span>
<button data-bind="click: $root.remove">delete</button>
</li>
</ul>
JavaScript
function Todo (title) {
this.title = title;
}
var ViewModel = function() {
var _this = this;
this.todos = ko.observableArray([new Todo("test1"), new Todo("test2")]);
this.title = ko.observable();
this.create = function () {
var title = this.title().trim();
if (title) {
_this.todos.push(new Todo(title));
}
}
this.remove = function (todo) {
_this.todos.remove(todo);
}
};
ko.applyBindings(new ViewModel());