Checking radio with Mustache
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" | |
"http://www.w3.org/TR/html4/loose.dtd"> | |
<html> | |
<head> | |
<title></title> | |
<script type="text/javascript" src="js/jquery-1.7.1.min.js"></script> | |
<script type="text/javascript" src="js/mustache.js"></script> | |
</head> | |
<body> | |
<div id="formWrapper"> | |
</div> | |
<script id="tmpl" type="x-template"> | |
<form> | |
{{#wrapped}} | |
<label><input type="radio" name="gender" value="male"> Male</label> | |
<label><input type="radio" name="gender" value="female"> Female</label> | |
{{/wrapped}} | |
</form> | |
</script> | |
<script type="text/javascript"> | |
var data = { | |
gender: 'female', | |
wrapped:function () { | |
return function (text) { | |
return text.replace('value="' + this.gender+'"', 'value="' + this.gender+'" checked'); | |
} | |
} | |
}; | |
var template = $("#tmpl").html(); | |
var result = Mustache.render(template, data); | |
$("#formWrapper").html(result); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.
see https://gist.github.com/1978729