javascript - Item in observable array is not added to the list KO -
i take data loaded list , add them observable array , suppose show them in list , goes except data not shown on screen here's code
self.adddata = function (val) { self.finallist().push(val); alert(val.latin_desc); }
<div class="container"> <h2> added servcies</h2> <div class="row" style="height:20vh; overflow:auto;"> <div class="col-md-3"> <ul data-bind="foreach:finallist"> <li class="list-group-item"> <div class="col-xs-3"> <b data-bind="text:latin_desc , value: sys_key"></b> </div> </li> </ul> </div> </div> </div>
exactly @connexo observablearray, , when binding b element, make sense use text , not value, since b element wont set change value.
function testvm (){ var self = this; self.finallist = ko.observablearray(); self.adddata = function (val) { self.finallist.push(val); alert(val.latin_desc); } self.adddata({latin_desc: 'rr', sys_key: 'gg'}); } ko.applybindings(new testvm())
<script src="https://cdnjs.cloudflare.com/ajax/libs/knockout/3.4.2/knockout-min.js"></script> <div class="container"> <h2> added servcies</h2> <div class="row" style="height:20vh; overflow:auto;"> <div class="col-md-3"> <ul data-bind="foreach:finallist"> <li class="list-group-item"> <div class="col-xs-3"> <b data-bind="text:latin_desc +'-'+ sys_key"></b> </div> </li> </ul> </div> </div> </div>
Comments
Post a Comment