jquery - Add dynamic values to the options of plugin -


i'm using jquery plugin http://amsul.ca/pickadate.js/date/

i'm in situation need add dynamic options/setting value plugin.

example of working settings:

$input = $('.datepicker').pickadate({               disable: [                   { from: [2015,5,10], to: [2015,5,17] }                  ]            }); 

i'm want create , date database , here code:

booking_dates array output:

 array     (         [0] => array             (                 [0] => 2015-06-02                 [1] => 2015-06-07             )          [1] => array             (                 [0] => 2015-06-10                 [1] => 2015-06-15             )          [2] => array             (                 [0] => 2015-06-16                 [1] => 2015-06-20             )      )  var booking_dates = ajax_object.booking_dates;                 var data = '';                 for(i = 0; < booking_dates.length; i++ ) {                     k = 0;                      var = booking_dates[i][k].split('-');                     var = booking_dates[i][++k].split('-');                      if(i == 0) {                         data = '{ from: [' + from[0] + ',' + (--from[1]) + ',' + from[2] + '], to: [' + to[0] + ','+ (--to[1]) + ',' + to[2] + '] }';                     } else {                         data = data + ', ' + '{ from: [' + from[0] + ',' + (--from[1]) + ',' + from[2] + '], to: [' + to[0] + ','+ (--to[1]) + ',' + to[2] + '] }';                     }                 }                       alert (data); //{ from: [2015,5,15], to: [2015,5,20]} 

data variable result is: { from: [2015,5,15], to: [2015,5,20] }

but when replace data settings not work:

does not work:

  $input = $('.datepicker').pickadate({                             disable: [                                data                             ]                     }); 

is string therefore not working? or have create options string in different way?

you need create array of objects instead creating string

var booking_dates = ajax_object.booking_dates; var data = []; (i = 0; < booking_dates.length; i++) {     k = 0;      var = booking_dates[i][k].split('-');     var = booking_dates[i][++k].split('-');      data.push({         from: [from[0], --from[1], from[2]],         to: [to[0], --to[1], to[2]]     }) }  alert(data);  $input = $('.datepicker').pickadate({     disable: data }); 

Comments