function createHeaders(ary) { var headers = {}; $(ary).each(function() { headers[this] = { sorter: false }; }); return headers; }
var a1 = [0,1,2], a2 = [0,4,5,8]; var h1 = createHeaders(a1), h2 = createHeaders(a2); $(this).tablesorter({ headers: h1 }); $(this).tablesorter({ headers: h2 }); - Richard On Thu, Sep 24, 2009 at 6:44 PM, macsig <sigbac...@gmail.com> wrote: > > I know this is not strictly related to jquery but I don't know how to > make it works. > > I'm working on a function that has as variable an array and for each > element I need to create a piece of code for an other function. > > For instance when the array contains [0,1,2] I need to call > > $(this).tablesorter({headers: {0: { sorter: false }, 1: { sorter: > false }, 2: { sorter: false }}}); > > > and when the array contains [0,4,5,8] I need to call > > $(this).tablesorter({headers: {0: { sorter: false }, 4: { sorter: > false }, 5: { sorter: false }, 8: { sorter: false }}}); > > > How can I achieve so? > > THANKS, I appreciate your help > > Sig