JSFiddle - React, Tailwind, and code Playground
HTML
<ul data-bind="foreach: items">
<li><span data-bind="text: id"></span>
<span data-bind="visible: $root.showName(name)">Yes!</span>
<a href="#" data-bind="click: $root.removePerson">Remove</a>
</li>
</ul>
JavaScript
var data = [{
id: 1,
name: "John Doe"
}, {
id: 2,
name: ""
}, {
id: 3,
name: "Peter Parker"
}];
var viewModel = {
items: ko.observableArray(data)
};
viewModel.showName = function (name) {
console.log(this);
return name && name.length > 0;
};
viewModel.removePerson = function () {
console.log(this);
};
ko.applyBindings(viewModel);