Created
February 6, 2013 08:44
-
-
Save pure/4721220 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 lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<title></title> | |
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script> | |
<script src="http://github.com/pure/pure/raw/master/libs/pure.js"></script> | |
</head> | |
<body> | |
<!-- main template --> | |
<ul class="animals"> | |
<li></li> | |
</ul> | |
<!-- sub template --> | |
<ol class="food"> | |
<li></li> | |
</ol> | |
<script> | |
var data = {animals:[ | |
{name:'bird', food:['seed','worm']}, | |
{name:'cat', food:['mouse', 'bird']}, | |
{name:'dog', food:['meat', 'bone']}, | |
{name:'mouse', food:['cheese', 'books']} | |
]}, | |
dirFood = { | |
'li':{ | |
'food<-':{ | |
'.':'food' | |
} | |
} | |
}, | |
//compile the sub template as a JS function | |
foodCompiled = $p('.food').compile(dirFood), | |
dirAnimals = { | |
'li':{ | |
'animal<-animals':{ | |
'.':'animal.name', | |
'.+':function(){ | |
//append to the current LI the subtemplate | |
return foodCompiled( this.food ); | |
} | |
} | |
} | |
}; | |
$('.animals').render(data, dirAnimals); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment