Last active
August 29, 2015 14:08
-
-
Save beebole/09f33882cce942943157 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>PURE Unobtrusive Rendering Engine</title> | |
<script src="http://pure.github.io/pure/libs/pure.js"></script> | |
</head> | |
<body> | |
<ul class="treeItem"> | |
<li> | |
<a class="name" href="javascript:void(0)">name</a> | |
<div class="children"></div> | |
</li> | |
</ul> | |
<script> | |
var data = {children: [{name: 'Europe',children: [{name: 'Belgium',children: [{name: 'Brussels',children:null},{name: 'Namur'},{name: 'Antwerpen'}]},{name: 'Germany'},{name: 'UK'}]},{name: 'America',children: [{name: 'US',children: [{name: 'Alabama'},{name: 'Georgia'}]},{name: 'Canada'},{name: 'Argentina'}]},{name: 'Asia'},{name: 'Africa'},{name: 'Antarctica'}]}, | |
directive = { | |
'li': { | |
'child <- children': { | |
'a': 'child.name', | |
'a@onclick':'alert(\'#{child.name}\');', | |
'div.children': function(ctxt){ | |
//here is where the recursion happens, calling the compiled function in itself by a closure | |
return ctxt.child.item.children ? rfn(ctxt.child.item):''; | |
} | |
} | |
} | |
}, | |
rfn = $p('ul').compile( directive ); | |
$p('ul').render( data, rfn ); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment