jquery - Create dynamic table from knockout view model with fixed first column -
i want create dynamic table based on days in month , apply knockout bindings on it. far i've created basic table , generated tds.
this ko view model:
var workermodel = function (_workerid, _workerfullname, _daysoftask) { this.workerid = _workerid; this.workerfullname = _workerfullname; this.daysoftask = _daysoftask; }; var appviewmodel = { daysinmonth: ko.observable(), workersarray: ko.observablearray(), getworkers: function () { // workers server } } i've created jsfiddle example: jsfiddle
problem is, don't know how determine if dayofmonth dayoftask , add html .
foreach: daysinmonth - create td
if (daysoftask[i] == dayofmonth) put html: "w" in td
also how can iterate ko.observable()? in fiddle i've put daysinmonth observablearray() duno how create for loop knockout. this:
daysinmonth = ko.observable(15);
< ko (i=0; < daysinmont; i++) >
... code
< /ko >
basicly want table layout:

you on right track.
you can use if binding conditionally display "w"s. need use indexof method (or if browser not supporting use of implementation exist in jquery, underscore.js, etc.) check whether current item in daysinmonth collection inside in daysoftask array.
you can current item daysinmonth $data property , actual daysoftask array $parent contextual binding properties:
<!-- ko foreach: $root.daysinmonth--> <td> <!-- ko if: $parent.daysoftask.indexof($data) != -1 --> w <!-- /ko --> </td> <!-- /ko --> demo jsfiddle.
Comments
Post a Comment