我尝试这样做,禁用所有日期并启用我通过参数传递的日期
这段代码不起作用
$.ajax({
method: "GET",
url: "url",
})
.success(function(msg) {
console.log(JSON.parse(msg));
var disableIni = JSON.parse(msg);
var disable = [];
for (var i = 0; i < disableIni.length; i++)
{
disable[i] = moment(disableIni[i][0] + "/" + disableIni[i][1] + "/" + disableIni[i][2], "M/DD/YYYY");
if (i > 5)
{
break;
}
}
console.log(disable);
var vectorTest = [moment("5/25/2017", "M/DD/YYYY"), moment("5/26/2017", "M/DD/YYYY"), moment("5/27/2017", "M/DD/YYYY")];
console.log(vectorTest);
var vector = disable;
console.log(vector);
$('#input_from').datetimepicker({
locale: 'es',
format: 'DD-MM-YYYY',
enabledDates: $.each(vector, function(i, value) {
return value;
})
});
});
但是,如果我改变var vector = disable了var vector = vectorTest,正常工作:
$.ajax({
method: "GET",
url: "url",
})
.success(function(msg) {
console.log(JSON.parse(msg));
var disableIni = JSON.parse(msg);
var disable = [];
for (var i = 0; i < disableIni.length; i++)
{
disable[i] = moment(disableIni[i][0] + "/" + disableIni[i][1] + "/" + disableIni[i][2], "M/DD/YYYY");
if (i > 5)
{
break;
}
}
console.log(disable);
var vectorTest = [moment("5/25/2017", "M/DD/YYYY"), moment("5/26/2017", "M/DD/YYYY"), moment("5/27/2017", "M/DD/YYYY")];
console.log(vectorTest);
var vector = vectorTest;
console.log(vector);
$('#input_from').datetimepicker({
locale: 'es',
format: 'DD-MM-YYYY',
enabledDates: $.each(vector, function(i, value) {
return value;
})
});
});
它有可能做到我想要的??
编辑
ajax响应:
它是一个包含3个位置的其他数组的数组.[0]=>月,[1]=>日,[2]=>年
谢谢