2016-03-25 112 views
-1

所以我有這個,我需要能夠輸出數組中的所有數組,包括括號。下面的例子通過顯式地調用索引來工作,但我似乎無法傳遞一個函數或for循環,期望表達式。另外,一個字符串不會。輸出帶括號的多維數組

for (var a in obj) { 
    var dateArray = []; 
    var date = new Date(obj[a]); 
    // var date = new Date('March 29, 2016 14:00:00'); 
    var hours = date.getHours(); 
    var minutes = date.getMinutes(); 
    console.log(date.toString()); 
    console.log(hours); 
    console.log(minutes); 
    dateArray[0] = hours; 
    dateArray[1] = minutes; 
    disabled_time_list.push(dateArray); 
} 
for (var i = 0; i < disabled_time_list.length; i++) { 
    console.log(disabled_time_list[i]); 
} 
pickertime.set('disable', [ 
    disabled_time_list[0] 
    // [14,0], 
]); 
+0

謝謝,是的,我想過之後,但不知道這將是必要的。也許應該把它放在標題中。 –

回答

0

如果沒有人需要它,這是我解決了這個問題:

$('.datepicker').change(function() { 
    var datepicker = $('.datepicker').pickadate(); 
    var pickerdate = datepicker.pickadate('picker'); 
    var dateInput = pickerdate.get('value'); 

    var request = $.ajax({ 
     type: "POST", 
     url: 'http://apptsch.dev/index.php/appointment/get_post_date', 
     data: { date: dateInput } 
    }).done(function(){ 
     disabled_time_list = []; 
     var timepicker = $('.timepicker').pickatime(); 
     var pickertime = timepicker.pickatime('picker'); 
     var times_disabled = pickertime.get('disable'); 
     console.log(times_disabled); 
     $.each(times_disabled,function(index, value) { 
      pickertime.set('enable', [ 
        times_disabled[index] 
       ]) 
     }); // end re-enable previously disabled times 

     var result = request.responseText; 

     var obj = jQuery.parseJSON(result); 

     for (var a in obj) { 
      var dateArray = []; 
      var date = new Date(obj[a]); 

      var hours = date.getHours(); 
      var minutes = date.getMinutes(); 
      dateArray[0] = hours; 
      dateArray[1] = minutes; 
      disabled_time_list.push(dateArray); 
     }      

     $.each(disabled_time_list,function(index, value) { 
      pickertime.set('disable', [ 

       disabled_time_list[index] 

      ]); //end disable 
     }); //end foreach 
    }); //end ajax call 
}); // end change