knockout.js - Math expressions with knockout through jquery.tmpl values? -


doing math expressions in jquery.tmpl knockout viewmodels doesn't seem work. there way this?

http://jsfiddle.net/z8f8r/

<p data-bind="text: number" /> <-- shows 10 expected  <script id="numbertemplate" type="text/html">     ${number} <-- shows 10 expected     ${number/2} <-- shows nan </script> 

enter image description here

the number value not actual value. it's function that, when called 0 arguments, returns expected value. when evaluate expression

${number / 2} 

you're doing same thing as

(function(){}) / 2 

which returns nan

if change expression instead

${number() / 2} 

you expected value of 5

you can see actual contents of number if eval value.

${eval(number)} 

returns function

function d(){     if(0<arguments.length)     {         if(!d.equalitycomparer||!d.equalitycomparer(c,arguments[0]))             d.h(),             c=arguments[0],             d.g();             return     }      b.r.wa(d);     return c } 

Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -