當我選擇的第一個選擇框中城市展示城市心軟數據如何使用j查詢在一個下拉列表中選擇選項時填充json?
如何填充的JSON選擇城市首次下降,當下降以及如何顯示心軟數據時,選擇不同的城市?
這是HTML
$(document).ready(function() {
var cityData = [{
cityName: 'Bengaluru',
value: "Bengaluru",
data: [{
movieName: 'ABC',
theaterName: 'Tulsi Theatre'
},
{
movieName: 'DEF',
theaterName: 'PVR'
},
{
movieName: 'GHI',
theaterName: 'Srinivasa Theatre'
}
]
},
{
cityName: 'Hyderabad',
value: "Hyderabad",
data: [{
movieName: '123',
theaterName: 'Theatre1'
},
{
movieName: '456',
theaterName: 'PVR2'
},
{
movieName: '789',
theaterName: 'Theatre3'
}
]
},
{
cityName: 'Guntur',
value: "Guntur",
data: [{
movieName: 'ABC1',
theaterName: 'Theatre4'
},
{
movieName: 'DEF2',
theaterName: 'PVR3'
},
{
movieName: 'GHI3',
theaterName: 'Theatre5'
}
]
},
{
cityName: 'Ongole',
value: "Ongole",
data: 'currently not available'
}
];
$("#selectCity").on('change', function() {
var locations = cityData[$(this).val()];
var locationString = 'locations';
console.log(locations)
$.each(locations, function(i, item) {
console.log(JSON.stringify(item));
// OUCH!!!
locationString += '<option value="' + item.id + '">' + item.name + '</option>';
});
//console.log(locationString)
$('#secondselectbox').html(locationString);
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="UserData">
<h1>MyMovie-Ticket-Booking</h1>
<select class="selectCity" id="selectCity">
\t \t \t \t <option value="City">Select City</option>
\t \t \t \t <option value="Bengaluru">Bengaluru</option>
\t \t \t \t <option value="Hyderabad">Hyderabad</option>
\t \t \t \t <option value="Guntur">Guntur</option>
\t \t \t \t <option value="Ongole">Ongole</option>
\t \t \t </select>
<span id="welcome"> </span>
</div>
<div>
<select id="secondselectbox"></select>
<select id="secondselectbox"></select>
</div>
當我選擇班加羅爾市秀卻是露出了不確定....
爲什麼用相同的ID有2'select'箱? – Varun
我想一次顯示劇院和電影名稱 – Babu