Created
July 11, 2011 03:19
-
-
Save micahalles/1075277 to your computer and use it in GitHub Desktop.
Nesting and Functions and Arrays, oh my!
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
var comments = [ | |
{ author: "Dave Crosby", approved: true, text: "Sounds Delicous!" }, | |
{ author: "Micah Alles", approved: false, text: "What next?!?" }, | |
{ author: "Drew Colthorp", approved: true, text: "Thanks for the info." } | |
]; | |
$("#my-template").expand({ | |
content: "Step 1, light the grill. Step 2...", | |
comments: function(el) { | |
var approvedComments = []; | |
$.each(comments, function(index, comment) { | |
if (comment.approved) { | |
approvedComments.push({ commenter: comment.author, body: comment.text }); | |
} | |
}); | |
if (approvedComments.length == 0) { | |
return false; | |
} else { | |
return approvedComments; | |
} | |
} | |
}) |
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
<div> | |
<span class="content">Step 1, light the grill. Step 2...</span> | |
<div class="comments"> | |
<div class="comment"> | |
<span class="commenter">Dave Crosby</span> | |
<div class="body">Sounds Delicous!</div> | |
</div> | |
<div class="comment"> | |
<span class="commenter">Drew Colthorp</span> | |
<div class="body">Thanks for the info.</div> | |
</div> | |
</div> | |
</div> |
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
<div id="my-template"> | |
<span class="content"></span> | |
<div class="comments"> | |
<div class="comment"> | |
<span class="commenter"></span> | |
<div class="body"></div> | |
</div> | |
</div> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment