wh" /> wh" /> wh"/>

rivets.js custom binders arguments

614 Views Asked by At

I just stated with rivets.js binders and have a simple problem. In my html file I've got a custom binder like <div rv-dashing-graph="mydata"></div> which returns the value of "mydata" to my binder.

In this I'm using it to set properties to this value:

rivets.binders['dashing-graph'] = function binder(el, data) {
if (!data) return;
// ...
if (/rickshaw_graph/.test(container.className)) {
    graph = window[container.dataset.id];
    graph.series[0].data = data;
    graph.update();
    return;
}

graph = new Rickshaw.Graph({
    element: container,
    width: container.width,
    height: container.height,
    series: [{
        color: '#fff', //white
        data: data
    }, ]
});

My problem is now that I'd like to have two data series in my Rickshaw graph, which is why I'd like to do something like

series: [{
                data: data, //the value of myData
                color: '#dfea34' 
        }, {
                data: data2, //value of second variable
                color: '#000' 
        }]

But how do I parse 2 values in my binder, so I can access "mydata" and "mysecondData" in the html file, but more specifically, how does the binder get that I want to have two variables?

1

There are 1 best solutions below

5
T J On

Just pass the entire series array to the binder like

<div rv-dashing-graph="series"></div>

You can iterate an access each objects inside it in the binder.