JSFiddle - React, Tailwind, and code Playground

by andersb79

HTML

<script src="http://github.com/downloads/SteveSanderson/knockout/knockout-2.1.0.js"></script>
<span>simple example</span></br>
<div data-bind="foreach : comments">
    <div><span data-bind="text:id"></span><span data-bind="text:text"></span></div>
</div>
</br></br>



<span>Somthing like this is what I want</span></br>
<div data-bind="myListView: {items:comments,SelectedItem : selectedComment}">
    <span>loop out comments</span>
</div>

JavaScript

ko.bindingHandlers.myListView = {
    init: function (element, valueAccessor) {
        var items = valueAccessor().items;        
    },
    update: function (element, valueAccessor, allBindingsAccessor, viewModel) {
        var items = valueAccessor().items;

    }
};

var Comment = function(id,text){
    this.text = ko.observable(text);
    this.id = ko.observable(id);    
};

var ViewModel = function(first, last) {
    this.comments = ko.observableArray([new Comment(1, "Comment1"),new Comment(2, "Comment2")]);

    this.selectedComment = ko.observable();

};

var vm = new ViewModel();
 
ko.applyBindings(vm);