How can do an (_?_:_) expression in polymer?

自作多情 提交于 2019-12-13 07:38:18

问题


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, "&#9679;" ,"&#9675;")}}</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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!