Closed dannyc closed 12 years ago
Hi @dannyc,
Thanks for the feature request and sorry for the late reply, I've been crazy busy lately. The feature request certainly makes sense. I think it through for a couple of days and come back with some ideas.
Cheers, Jarno
Here's how you can do it with directives:
CoffeeScript:
people = [
civil_id: '123456'
name: 'Foo Bar'
,
civil_id: '654321'
name: 'Fizz Buzz'
]
admin = true
directives =
civil_id: text: (p) -> $(p.element).remove() unless admin
$('.people').render people, directives
Tempate (in Jade):
ul.people
li
span.civil_id
span.name
Result
<ul class="people">
<li>
<span class="civil_id">123456</span>
<span class="name">Foo Bar</span>
</li>
<li>
<span class="civil_id">654321</span>
<span class="name">Fizz Buzz</span>
</li>
</ul>
Civil ID field can be toggled on/off by setting admin
to true
or false
.
Feature request: Would be nice to have ability to not generate dom elements based on a directive or the data object, instead of generating them and setting display: none. This is the equivalent of "if" statements in other template solutions. For example if I have a button or text field to display only if the logged in user is an admin, I'd prefer to skip the render stage and just move on. Something like:
Would result in:
Or as a directive: Template:
Javascript:
Result:
Thoughts?