javascript - Knockout template not rendering off a computed observable -
below 2 knockout templates plugin , plugin2. both dependent upon ko.computed observables , both observables have deferevaluation property set true. plugin does not render, plugin2 does render.
what needs changed create plugin render (keeping deferevaluation==true)?
fiddle here http://jsfiddle.net/jeljeljel/yklgm/
html
<div id="plugin" data-bind="template: { name: 'template1', data: $data }" ></div> <div id="plugin2" data-bind="template: { name: 'template2', data: $data }" ></div> <script type="text/html" id="template1"> <div data-bind="foreach: columns()"> <span data-bind="text: displaytext"></span> </div> </script> <script type="text/html" id="template2"> <div data-bind="text: dataitem" ></div> </script>
javascript
var griddata = { columns: [{ displaytext: 'name' }, { displaytext: 'last login date' }, { displaytext: 'email' }] }; function datamodel() { var self = this; self.columns = ko.observablearray([]); self.loadgrid = ko.computed({ read: function () { self.columns(griddata.columns); }, owner: this, deferevaluation: true }); self.id = ko.observable(1); self.dataitem = ko.computed({ read: function () { homecoming self.id() * 3; }, owner: this, deferevaluation: true }); } datamodel = new datamodel(); ko.applybindings(datamodel);
both dependent upon ko.computed observables
no, not. plugin
depends on columns
, empty observablearray never gets populated. maybe should use loadgrid
computed observable somewhere.
by way, loadgrid
not create much sense computed observable in current state, read method not homecoming anything.
javascript knockout.js
No comments:
Post a Comment