Search code examples
rivets.js

Rivets.js bind more than once


I'm working with Rivets.js and want to bind to more than one data object. When I bind twice the latter bind does nothing. I've tried unbinding the first bind before attempting to bind the second data object with no luck.


Solution

  • Provide to rivets.bind() an object with all your data objects (models), nested inside.

    var data1 = { name : 'data1' };
    var data2 = { name : 'data2'};
    var body = document.getElementsByTagName("body")[0];
    rivets.bind( body , { a : data1, b : data2 } );
    

    To test previous binding, try with following the HTML:

    <body>
        <div>{a.name}</div>
        <div>{b.name}</div>
    </body>