Created
October 17, 2013 21:09
-
-
Save pure/7032248 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://pure.github.io/pure/libs/pure.js"></script> | |
</head> | |
<body> | |
<!-- main template --> | |
<div class="animals"> | |
<select class="food"> | |
<option></option> | |
</select> | |
</div> | |
<!-- sub template --> | |
<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 = { | |
'option':{ | |
'food<-':{ | |
'.':'food' | |
} | |
} | |
}, | |
//compile the sub template as a JS function | |
foodCompiled = $p('.food').compile(dirFood), | |
dirAnimals = { | |
'select':{ | |
'animal<-animals':{ | |
'@class':'animal.name', | |
'.':function(){ | |
return foodCompiled( this.food ).replace(/\s*<\/?select[^\>]*>\s*/g, ''); | |
} | |
} | |
} | |
}; | |
$('.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