Lần đầu tiên, Khi tôi tải trang, chọn hộp của tôi là rỗng:JQuery Mobile: Làm cách nào để hiển thị lại hộp chọn?
<select name="secondaryTitle" id="secondaryTitle"></select>
Sau đó, tôi thực hiện cuộc gọi ajax và lấy dữ liệu json cho hộp chọn ở trên.
arrtitle = objSecTitle.getAllSecondaryTitle(serviceId); // its an ajax call, that returns json object
var obj = jQuery("#secondaryTitle");
removeAllOptions(obj);
for(i=0;i<arrtitle.length;i++)
{
obj.options.length=obj.options.length + 1;
obj.options[obj.options.length - 1].text = arrtitle[i][1];
obj.options[obj.options.length - 1].value = arrtitle[i][0];
}
function removeAllOptions(selectbox){
var i;
for(i=selectbox.options.length-1;i>=0;i--)
{
selectbox.remove(i);
}
}
Cuộc gọi ajax của tôi là hoàn hảo. Mã trên cũng thay đổi các mục thả xuống. Nhưng giao diện người dùng sẽ không được cập nhật khi chúng tôi sử dụng jQuery Mobile, vì nó hiển thị/ẩn div khác nhau cho cửa sổ bật lên lựa chọn.
OMG điều này khiến tôi mất nhiều thời gian để tìm! Tôi đã thử mọi thứ trong nhiều ngày nay. Cảm ơn! –
bạn nên sử dụng tốt hơn .trigger ('create') – TecHunter