Created
December 6, 2009 10:43
-
-
Save pure/250156 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>PURE Unobtrusive Rendering Engine</title> | |
<script src="../libs/jquery.js"></script> | |
<script src="../libs/pure.js"></script> | |
<style> | |
.even td { background : #DDD } | |
.odd td { background : #FFF } | |
</style> | |
</head> | |
<body> | |
<!-- HTML template --> | |
<table> | |
<tr> | |
<td></td> | |
</tr> | |
</table> | |
<script> | |
var directive = { | |
//trigger a loop | |
'tr' : { | |
// loop on the property animals in the JSON | |
'animal<-animals' : { | |
// add(+) the return value of the function to the class | |
'@class+':function(arg){ | |
var oddEven, firstLast; | |
oddEven = (arg.pos % 2 == 0) ? ' even' : ' odd'; | |
firstLast = (arg.pos == 0) ? | |
' first' : | |
(arg.pos == arg.animal.items.length - 1) ? | |
' last' : | |
''; | |
return oddEven + firstLast; | |
}, | |
'td':'animal.name' | |
} | |
} | |
}; | |
var data = { | |
animals:[ | |
{name:'bird'}, | |
{name:'cat'}, | |
{name:'dog'}, | |
{name:'mouse'} | |
] | |
}; | |
$('table').render(data, directive); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment