How to bind two values using rivets(like some or condittion)?

不想你离开。 提交于 2019-12-11 08:59:34

问题


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

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