javascript - Knockout not rendering -
scenario:
i have viewmodel has list of grades in it. need knockout render grades, names fine.
current output:
the info beingness captured viewmodel. know because of series of console.log() statements in code homecoming expect return.
expected output:
just series of <p> tags name of grade in them.
links:
fiddle: here
pastebin: here
current code:
<html> <head> <title></title> <?php include "./includes/functions.php"; ?> <script type="text/javascript" src="js/vendor/ko.js"></script> <script type="text/javascript" src="js/vendor/ko-mapping.js"></script> <script type="text/javascript"> function load() { var parsedjson = <?php echo json_encode(populategrades()) ?>; console.log(parsedjson); function grade (id, name, springpressure) { this.id = ko.observable(id); this.name = ko.observable(name); this.springpressure = ko.observable(springpressure); } function viewmodel() { var self = this; self.grades = ko.utils.arraymap(parsedjson, function(item) { homecoming new grade(item.id, item.name, item.springpressure); }); console.log(self.grades); self.chosengrade = ko.observable(); self.json = ko.tojson(self.grades); } ko.applybindings(new viewmodel()); } </script> </head> <body onload="load()"> <!-- ko foreach: grades --> <p data-bind="name"></p> <!-- /ko --> </body> </html> any feedback , or comments welcomed, , appreciated.
it's pretty simple typo: field names wrong:
self.grades = ko.utils.arraymap(parsedjson, function (item) { homecoming new grade(item.gradeid, item.name, item.springpressure); }); working example: http://jsfiddle.net/czln4/2/
javascript knockout.js
No comments:
Post a Comment