views:

97

answers:

1

jsRepeater (a template engine for jquery) has output formatting that let's you pass the template engine a function that will execute before the engine renders the final value.

when I'm looping through an array of values I'd like the formatting function to receive the whole array in addition to just the one value.

how can I modify the formatting function call so it get's the single value and the array? I tried hopelessly fumbling through the code but couldn't figure it out.

Data Example:

var data = {items:[{"file_name":"test1.txt", "file_size":5000,"bytes_sent":2500},     
{"file_name":"test2.txt", "file_size":6000, "bytes_sent":3000}]};

Template Example:

<div>Bytes Remaining: ${file_size:formatRemaining}</div>

Formatting Function:

  function formatRemaining(data, row) {  
  var remaining = data - row[bytes_sent];
  return remaining;
}

In this example I'd like my formatting function to do a calculation on "file size" and "bytes sent" in order to output the remaining number of bytes to be sent.

A: 

I ended up creating my own jquery plugin that does exactly what I was looking for.

rawberg