After jQuery obtains json, it uses zy_tmpl to generate a drop-down menu.
This article mainly introduces how to use jQuery to obtain json and then use zy_tmpl to generate a drop-down menu instance. Although it is the first time to write about AppCan development, if you need it, you can refer to it.
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
The Code is as follows:
Echo $ _ GET ['jsoncallback']. "(". json_encode ($ res ).")";
In the AppCan template, add a drop-down menu. My menu is:
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
<! -- 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> </Div> </Div> <! -- The drop-down list ends --> |
Then join in:
?
1 2 3 4 5 6 7 |
Function getscsi (){ $. 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.