第一次,當我打開網頁,我的選擇框爲空:JQuery Mobile:如何重新渲染選擇框?
<select name="secondaryTitle" id="secondaryTitle"></select>
然後我讓Ajax調用,並得到JSON數據上面選擇框。
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);
}
}
我的ajax調用是完美的。以上代碼也會更改下拉項目。但是,當我們使用jQuery Mobile時,UI將不會被更新,因爲它顯示/隱藏不同的div用於選擇彈出窗口。
OMG這花了我這麼長時間才找到!我已經嘗試了幾天的一切。謝謝! – 2011-11-24 14:19:52