如何訪問@location.coordinates
數據並將其用於查詢的GetMarineWeather()
函數中?使用Rails數據實現Javascript功能
我希望能夠使用rails數據並加載查詢座標。
如何在最初加載頁面時訪問座標並填充函數?
<p id="notice"><%= notice %></p>
<p><strong>Name:</strong><%= @location.name %></p>
<p><strong>Sub region:</strong><%= @location.sub_region %></p>
<p><strong>Region:</strong><%= @location.region %></p>
<p><strong>Coordinates:</strong><%= @location.coordinates %></p>
<div id="resultContainer"></div>
<!-- *********************************************************************** -->
<script type="text/javascript">
var resultContainer = $('#resultContainer');
var output = '';
$(document).ready(function() {
GetMarineWeather();
});
function GetMarineWeather(e) {
var marineWeatherInput = {
query: '26.16,-80.10',
format: 'JSON',
fx: '',
callback: 'MarineWeatherCallback'
};
JSONP_MarineWeather(marineWeatherInput);
e.preventDefault();
}
function MarineWeatherCallback(marineWeather) {
output = "<br/> Date: " + marineWeather.data.weather[0].date;
output += "<br/> Min Temp (f): " + marineWeather.data.weather[0].mintempF;
output += "<br/> Max Temp (f): " + marineWeather.data.weather[0].maxtempF;
output += "<br/> Cloud Cover: " + marineWeather.data.weather[0].hourly[0].cloudcover;
resultContainer.empty();
resultContainer.html(output);
}
</script>