Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
238 views
in Technique[技术] by (71.8m points)

javascript - HTML 1st option in select is not render selected item on page Jquery mobile?

I have problem with html select when I bind the json to html select it will not show the 1st item on web page when I load the page first time

enter image description here

Html

 <div data-role="collapsible-set" id="poset">
<div data-role="collapsible" data-collapsed="false">
<h3>OP Select</h3>
<div class="ui-grid-b">
   <div class="ui-block-a">
      <div style="padding-top: 15px;">Vendor #</div>
   </div>
   <div class="ui-block-b">
      <select id="vendorno">
      </select>
   </div>
   <div class="ui-block-c">
      <button type="submit" id="chooseVendor">Select</button>
   </div>
</div>
<div class="ui-grid-b" id="poGrid">
   <div class="ui-block-a">
      <div style="padding-top: 15px;">PO #</div>
   </div>
   <div class="ui-block-b">
      <select id="POno">
      </select>
   </div>
   <div class="ui-block-c">
      <button type="submit" id="choosePONum">Select</button>
   </div>
</div>

javascript

$('#poGrid').hide();
$('#poInfos').hide();
var rootURLgetVendornosList = "webresources/vendors/getVendornosList";
//var rootURLgetVendornosList = "http://:8080/Info5059Case2v-war/webresources/vendors/getVendornosList";


$.getJSON(rootURLgetVendornosList,null,function(data,status,jqXHR){
        renderVendorList(data);
    }).error(function(jqXHR,textStatus,errorThrown){
        console.log(textStatus+"-"+errorThrown);
    });
//bind select #vendorno
function renderVendorList(data)
{
    $(data).each(function(){
        $('#vendorno').append("<option>"+ this +"</option>");
    });
}




var rootURL3 = "webresources/PO/";
//var rootURL3 = "http://:8080/Info5059Case2v-war/webresources/PO/";


//bind select op select 
 $("#chooseVendor").click(function(){
    $.getJSON(rootURL3 + "getALLPOForVendor/" + $('#vendorno').val(),null,function(data,status,jqXHR){
        renderPOList(data);
    }).error(function(jqXHR,textStatus,errorThrown){
        console.log(textStatus+"-"+errorThrown);
    });

});//chooseVendor
//bind select POno
function renderPOList(data)
{
        $(data).each(function(){
        $('#POno').append("<option>"+ this.ponumber +"</option>");
    });
     $('#poGrid').show();
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

After appending items into select menu, you need to re-enhance / re-apply JQM styles. For select menu, call the below.

$(".selector").selectmenu("refresh");

Reference: Selectmenu widget API


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...