【发布时间】:2015-04-22 12:47:56
【问题描述】:
我正在尝试使用来自多个 json 对象的 'startDate' 的值填充下拉列表,如何在不显示 'endDate' 和 'price' 的情况下做到这一点?
这是我目前的情况:
这是我正在使用的代码:
function get_months(year) {
selected_year = year;
date.style.visibility = 'hidden';
month.style.visibility = 'visible';
yearArray = dateType[year];
console.log(yearArray);
$.each(yearArray, function(key, value) {
$(month).append('<option value=' + value + '>' + key + '</option>');
});
}
function get_dates(month) {
date_selected = false;
if(current_type == 'Weekend') {
date.style.visibility = 'visible';
//console.log(current_customer, current_type, selected_year, month);
} else if(current_type == 'Midweek') {
date.style.visibility = 'visible';
//console.log(current_customer, current_type, selected_year, month);
} else if(current_type == 'Week') {
date.style.visibility = 'visible';
//console.log(current_customer, current_type, selected_year, month);
}
monthArray = yearArray[month];
console.log(monthArray);
alert(monthArray);
$.each(monthArray, function(key, value) {
//startDate = value.startDate;
console.log(value.startDate);
$.each(value, function(key2, value2) {
/* console.log(key2);
console.log(value2); */
$(date).append('<option value=' + key2 + '>' + value2 + '</option>');
});
});
}
如果需要任何其他信息,请询问! 提前致谢!
【问题讨论】:
-
您到底在寻找什么?您想从 JSON 中提取日期部分吗?
-
@MokshShah 正如您在当前情况的图像中看到的那样,它显示了所有 3 个对象的“startDate”、“endDate”和“price”。我只想在所有 3 个对象的下拉列表中显示“startDate”的值。
-
你能发布你的 JSON 吗?