JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://ajax.aspnetcdn.com/ajax/knockout/knockout-3.3.0.js"></script>
<div data-bind="component: { name: 'root', params: { model: $root } }"></div>
<script id="root_template" type="text/html">
<div>
<span data-bind="text: title"></div>
<div data-bind="with: rootViewModel">
<input type="text" data-bind="value: rootText" />
<button data-bind="click: rootFunc">Go</button>
</div>
</div>
</script>
JavaScript
var RootViewModel = function() {
var self = this;
this.rootText = ko.observable('default text');
this.rootFunc = function() {
alert("root func!");
};
}
ko.components.register('root', {
viewModel: function(model) {
var self = this;
this.rootViewModel = model;
this.title = ko.observable('default title');
},
template: { element: 'root_template' }
});
ko.applyBindings(new RootViewModel());