After jQuery obtains json, it uses zy_tmpl to generate the drop-down menu, jsonzy_tmpl
The first time I wrote an article about AppCan development, someone wrote about jQuery or native Ajax interaction with json, then I will write a little bit about the example of generating a drop-down menu using zy_tmpl after obtaining json using jQuery during the development process.
The json part generated by the PHP server is not written so much, that is, an array $ res is input, and then
Copy codeThe Code is as follows:
Echo $ _ GET ['jsoncallback']. "(". json_encode ($ res ).")";
In the AppCan template, add a drop-down menu. My menu is:
<! -- Start from the drop-down list --> <div class = "ui-has-label"> <label class = "ui-select"> select a group: </label> <div class = "ui-select"> <div class = "ui-btn-icon-right ui-btn-corner-all ui-btn- B "> <span class =" ui-btn-inner ui-btn-corner-all "> <span class =" ui-btn-text "> building name </span> <div class = "ui-li-link-alt ui-btn-corner-right ui-shadow"> <span class = "ui-icon-arrow- d ui-icon-shadow "> </span> </div> </span> <select Name = "lc" id = "lc" selectedIndex = "0" id = "select-choice-0" onchange = "zy_slectmenu (this. id) "> loading data. Please wait </select> </div> <! -- The drop-down list ends -->
Then join in:
function getlq(){ $.getJSON('http://localhost/json.php?jsoncallback=?', function(data) { var tmpl='<option value="${BuildingId}">${BuildingName}</option>'; $("#lc").html(""); $("#lc").append(zy_tmpl(tmpl,data,zy_tmpl_count(data))); })}
In this way, when onload, onchange, and onclick are executed, the select update can be implemented.
The above is all the content of this article. I hope you will like it.
Please take a moment to share your article with your friends or leave a comment. Thank you for your support!