如何在聚合物中表达(_?_:_)? [英] How can do an (_?_:_) expression in polymer?
本文介绍了如何在聚合物中表达(_?_:_)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在JSP中有这样的东西:
I have something like this in JSP:
<td>${job.invoiced ? "Y" : "N" }</td>
我将如何在Polymer 1.0中做一些等效的事情:
How would I do something equivalent in Polymer 1.0:
<td>{{job.invoiced ? "Y" : "N"}}</td> <!-- does not work -->
推荐答案
解决问题的一种方法是定义一个名为iff的JS函数,然后在您的表达式中使用它:
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>
这是我定义iff函数的方式:
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>
这篇关于如何在聚合物中表达(_?_:_)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文