Rivets.js bind more than once

339 Views Asked by At

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.

1

There are 1 best solutions below

0
colxi On BEST ANSWER

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>