【发布时间】:2014-04-27 02:50:15
【问题描述】:
是否有官方文档解释函数参数的工作原理?
$.getJSON("files/golfClubs.json", function (data) {
$.each(data, function (index, value) {
$("#filtermenu").append("<option value='" + data[0].GolfCourses[index].GolfCourseID + "'>" + data[0].GolfCourses[index].GolfCourseName + " </option>");
});
});
比如说:
$.getJSON("files/golfClubs.json", function (data) {
alert(data);
//Returns undefined. Unless .JSON.stringify-ed().
});
问题 1:我想知道当您引用相同的参数变量时,参数基本上是如何传递数据的。尤其是嵌套的 JSON。当您传递 2 个参数而不是 1 个参数时会发生什么?
问题 2:结合函数中的参数,使用下面的 JSON,您如何访问 GolfCourses.GolfCourseBookings.DayBookings?
[
{
"GolfClubID": "TROPICANA",
"GolfClubName": "Tropicana Golf and Country Club",
"GolfCourses": [
{
"GolfCourseID": "1",
"GolfCourseName": "West Course - 1st 9",
"GolfCourseBookings": [
{
"DayNumber": 1,
"DayDate": "19/03/2014",
"DayBookings": [
{
"TimeSlotID": "0",
"Time" : "07:00",
"Class": "Closed"
},
{
"TimeSlotID": "1",
"Time" : "07:10",
"Class": "Closed"
},
{
"TimeSlotID": "2",
"Time" : "07:20",
"Class": "Closed"
},
【问题讨论】:
-
你的数据是嵌套数组对象,所以你可以访问数据,比如 alert(data[0])
-
value[0].GolfCourses[index].GolfCourseID不是data[0].......。
标签: jquery ajax json jquery-mobile getjson