问题
I want to bind two values to a DOM element using rivets like user.name and user.id so that it will take user.name if it is there or user.id if user.name is empty. Can someone tell me if this is possible??
回答1:
You could use a oneway binder to achieve this
http://rivetsjs.com/docs/guide/#binders
An example is at http://jsfiddle.net/jWVDu/1/
<li rv-each-person="people" rv-data-pid="person.id">
<span rv-nameorid="person.name"></span>
Basically set up a new data attribute for the id (rv-data-pid), then pass the name to the binder (rv-nameorid). the binder then checks value (name) and if it is blank uses it, otherwise it uses the data attribute which has the id.
来源:https://stackoverflow.com/questions/23952822/how-to-bind-two-values-using-rivetslike-some-or-condittion