2017-10-03 4 views
1

Je souhaite que les dates sélectionnées provenant du fichier JSON soient surlignées en arrière-plan rouge sur DateTimePicker.Pourquoi les dates ne sont pas mises en surbrillance dans datetimepicker?

Je passe des dates en utilisant l'appel ajax de Jquery. Les dates sont au format MMDDYYYY stocké dans le fichier JSON date.json.

Mon code JS est ceci:

$(function() { 
    $('#datetimepicker5').datetimepicker({ 
     defaultDate: "10/01/2017", 
     disabledDates: [ moment("10/05/2017"), 
      new Date(2018, 11 - 1, 21), 
      "11/22/2017", "11/23/2017"] 
    }); 
}); 

$.ajax({ 
    type: "GET", 
    url: "date.json", 
    success: function (data) 
    { 
     var count = Object.keys(data).length; 
     for(var i=0;i<count;i++) 
     { 
      var a = data[i].date; 
      $("#datetimepicker5").datetimepicker({ 
       beforeShowDay: function(a) 
       { 
        var Highlight = a; 
        if(Highlight){ 

         return[true, "Highlighted", Highlight]; 
        } 
        else { 
         return ['true','','']; 
        } 
       } 
      }); 
      { 
      } 
     } 
    }, 
}, 
    dataType: "json" 
}); 

Et CSS Code est ceci:

.Highlighted a{ 
    background-color : Green !important; 
    background-image :none !important; 
    color: White !important; 
    font-weight:bold !important; 
    font-size: 12pt; 
} 

td.highlight { 
    background-color: red; 
    border: 1px blue solid; 
} 

Voici le JSON données:

[ 
    {"date":"10/05/2017"}, 
    {"date":"10/09/2017"}, 
    {"date":"10/02/2017"}, 
    {"date":"10/10/2017"} 
] 
+0

L'appel ajax est en dehors de la fonction '.ready'. 'dataType:" json "' est en dehors de l'appel ajax. En outre, il a plusieurs parenthèses fermantes manquantes. – adiga

+0

Vous avez une erreur de syntaxe, je pense!? 'else { return ['true', '', '']; }} }) { }} }, }, dataType: "JSON" ' – Meloman

Répondre

0

Pour votre JS j'ai juste corrigé l'indentation et ai trouvé le problème.

$(function() { 
    $('#datetimepicker5').datetimepicker({ 
     defaultDate: '10/01/2017', 
     disabledDates: [ 
      moment('10/05/2017'), 
      new Date(2018, 11 - 1, 21), 
      '11/22/2017', 
      '11/23/2017' 
     ] 
    }); 
    $.ajax({ 
     type:  'GET', 
     url:  'date.json', 
     dataType: 'json', 
     success: function(data) { 
      var count = Object.keys(data).length; 
      for(var i=0; i<count; i++) { 
       var a = data[i].date; 
       $('#datetimepicker5').datetimepicker({ 
        beforeShowDay: function(a) { 
         var Highlight = a; 
         if(Highlight) { 
          return [ 
           'true', 
           'Highlighted', 
           'Highlight' 
          ]; 
         } 
         else { 
          return [ 
           'true', 
           '', 
           '' 
          ]; 
         } 
        } 
       }); 
      } 
     } 
    }); 
});