knockouttest

by subhadipghosh

HTML

<div id="div_test">
    <ul data-bind="foreach: products">
        <li><label data-bind="text: $index" ></label>&nbsp;
            <span data-bind="text: name"></span>&nbsp;
            <div data-bind="ifnot: rate > 20"><span data-bind="text: rate"></span></div>
            <div data-bind="with:plot">
                <span data-bind="text: width + '-' +height"></span></div>  
            <a data-bind="attr: {href:'#/'+name}" >click</a>           
            <div data-bind="if: address!=''"><span data-bind="text: address"></span></div>
           
        </li>
    </ul>
    <button data-bind="click: onclick">Click</button>
</div>

JavaScript

function scope(){
    var $scope=this;
    $scope.products=[{name:"test",address:"agarpara",rate:22,plot:{width:1110,height:800}},            {name:"test2",rate:18,plot:{width:1500,height:600}}];
    $scope.onclick=function(){
        alert("Clicked");
    };
}

ko.applyBindings(new scope(),document.getElementById("div_test"));