css - using a javascript function in a Knockout style binding -
css - using a javascript function in a Knockout style binding -
i have html page have applied knockout bindings elements:
<td class="tepvval" data-bind="text: tepv"></td> <td class="dateval" data-bind="text: duein(due)"></td>
in sec element, phone call function populate info content of element. i'm trying same style of element, i'm having issues. need phone call function compute difference between date (due) , today, , homecoming color want utilize background of element - greenish due more 30 days, yellowish 30-15 days, orange 15-1 days, reddish overdue.
i tried using
<td class="dateval" data-bind="text: duein(due), style: { backgroundcolor: colordue(due) }"></td>
but doesn't work.
what missing in syntax?
here function code i'm calling in colordue:
function colordue(due) { rd = 1; od = 15; yd = 30; var difference = datediff(due); if (difference>yd) { color="green"; } else if (yd>difference && difference>od) { color="yellow"; } else if (od>difference && difference>rd) { color="orange"; } else if (difference <=rd) { color="red"; } homecoming color; } function datediff(due) { var df, ymd, now, datestr, diff; df = due.split(" "); ymd = df[0].split("-"); = new date(); datestr = new date(ymd[0],ymd[1],ymd[2],17,0,0); diff = datestr.gettime()-now.gettime(); diff = diff/86400000; homecoming diff; }
your problem here:
datestr = new date(ymd[0],ymd[1],ymd[2],17,0,0);
in js (don't inquire why), month starts @ 0 (while day , year starts @ 1...). see doc
month integer value representing month, origin 0 jan 11 december.
so need -1
here:
datestr = new date(ymd[0],ymd[1] -1,ymd[2],17,0,0);
there other stuff should alter here, declaring variables local:
function colordue(due) { var rd = 1; var od = 15; var yd = 30; var color = ""; //... }
javascript css knockout.js
Comments
Post a Comment