I'n using knockout js and jQuery templates. So i want to render some model with name and date. Problem is in Date field. I've wrote function that print date in my language natural form, and want to use it in template.
I've wrote this template:
<script type="text/html" id="item-template">
${Name} (${Date().toRussianDateString()})
</script>
but recived error Uncaught SyntaxError: Unexpected token )
So i've found this solution:
<script type="text/html" id="item-template">
${Name} (${$data.Date().toRussianDateString()})
</script>
of using $data and $item variables. Is right solution? Can i wrote this template without using $date and $item?
Thanx.
It's a little dirty because you're mixing the dead-in-the-water jquery.tmpl engine with native KO templates.
If you're able to use the latest version of KO, you can just write this:
<div data-bind="foreach: items">
$data.Name ($data.Date().toRussianDateString())
</div>
Notice that is inline; you don't need any separate script block or named templates.