Skip to content

recipes_livebindings

Josh Dean edited this page Jun 30, 2013 · 3 revisions

@page RecipesLiveBindings Live Bindings @parent Recipes 1

@body The following recipes show how to use can.EJS's live binding.

Updating timestamps

The following shows how to create an automatically updating prettyDate helper for EJS that can be used like:

@codestart <%= prettyDate( new Date() ) %> @codeend

Notice how the created value changes every couple min or so.

The prettyDate method works with or without live-binding. It doesn't need to take an observe, just a date. Code with EJS becomes live naturally ... amazing.

<iframe style="width: 100%; height: 300px" src="http://jsfiddle.net/donejs/gvsZj/embedded/result,html,js,css" allowfullscreen="allowfullscreen" frameborder="0">JSFiddle</iframe>

2-way binding Mustache helpers

Learn how to make 2-way binding mustache helpers. When you change the value of an input, it automatically changes the value of an observe. When you change the value of the observe, it changes the value of the input.

<iframe style="width: 100%; height: 300px" src="http://jsfiddle.net/donejs/dffJ7/embedded/result,html,js,css" allowfullscreen="allowfullscreen" frameborder="0">JSFiddle</iframe>

How it works

Clone this wiki locally