在 JavaScript 代码的末尾,您可以找到 function(xml)。
在其中您可以编写 console.log(xml) 然后在控制台(开发人员工具)中检查数据的结构是什么。
如果您确实想更改演示的代码,则必须以相同的格式写入数据。
您可以查看代码以了解确切需要什么,因为并非所有数据都已使用。基于此,您可以禁用 ajax 调用并手动创建数据对象。
示例:http: //jsfiddle.net/qLynjzds/
演示中数据如何工作的示例(2 分):
var xml = {
credit: {
link: {
'@attributes': {
url: "http://www.yr.no/place/United_Kingdom/England/London/" //link for credits
}
}
},
location: {
country: "Country",
name: "City"
},
forecast: {
tabular: {
time: [{
'@attributes': {
from: "2015-05-28T14:00:00",
to: "2015-05-28T15:00:00"
},
symbol: {
'@attributes': {
'var': "01d",
name: "Clear sky"
},
},
temperature: {
'@attributes': {
value: "17"
},
},
precipitation: {
'@attributes': {
value: "0"
},
},
windDirection: {
'@attributes': {
deg: "252.6",
name: "West"
},
},
windSpeed: {
'@attributes': {
mps: "16.6",
name: "Strong breeze"
},
},
pressure: {
'@attributes': {
value: "1013.8"
},
}
}, {
'@attributes': {
from: "2015-05-28T15:00:00",
to: "2015-05-28T16:00:00"
},
symbol: {
'@attributes': {
'var': "01d",
name: "Clear sky"
},
},
temperature: {
'@attributes': {
value: "15"
},
},
precipitation: {
'@attributes': {
value: "1"
},
},
windDirection: {
'@attributes': {
deg: "252.6",
name: "West"
},
},
windSpeed: {
'@attributes': {
mps: "16.6",
name: "Strong breeze"
},
},
pressure: {
'@attributes': {
value: "1010.8"
},
}
}]
}
}
};