javascript - How to put together an options object in flot -


i have following javascript:

  if(i==1&&$('#ln').val()=='true')     ops={       xaxis: {show:false},       yaxis: {show:false,               transform: function (v) { return -v; },               inversetransform: function (v) { return -v; }}}   else ops={xaxis: {show:false}, yaxis: {show:false}};   $.plot($(gr), pdat,ops); 

when tried make string of ops got errors on parsing it. suppose it's because of functions. how can put options can add other options according different conditions? in example idea avoid repeating xaxis: {show:false}, yaxis: {show:false}

you can populate ops object common properties , add others in if statement:

  // initalize ops common properties   var ops = {       xaxis: {show: false},       yaxis: {show: false}   };   if (i == 1 && $('#ln').val() == 'true') {       ops.yaxis.transform = function (v) { return -v; };       ops.yaxis.inversetransform = function (v) { return -v; };   }   $.plot($(gr), pdat, ops); 

Comments

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -