问题
I have something like this in JSP:
<td>${job.invoiced ? "Y" : "N" }</td>
How would I do something equivalent in Polymer 1.0:
<td>{{job.invoiced ? "Y" : "N"}}</td> <!-- does not work -->
回答1:
One way to solve the problem is to define a JS function called iff and then use that in your expression:
<td>{{iff(j.invoiced, "●" ,"○")}}</td>
Here is how I defined the iff function:
<script>
Polymer({
is: "job-audit",
properties: {
jobs: {
type: Array,
notify: true
}
},
iff(test,t,f){
return test?t:f;
}
});
</script>
来源:https://stackoverflow.com/questions/34754824/how-can-do-an-expression-in-polymer