Home Backend Development PHP Tutorial jQuery获取json后使用zy_tmpl生成下拉菜单_php技巧

jQuery获取json后使用zy_tmpl生成下拉菜单_php技巧

May 16, 2016 pm 08:19 PM
jquery json Drop-down menu

第一次写关于AppCan开发的文章,有人写了关于jQuery或者原生Ajax与json的交互,那我就稍微写写我开发过程中使用jQuery获取json后使用zy_tmpl生成下拉菜单的实例吧。

PHP服务端生成json的那部分就不写那么多了,就是输入一个数组$res,然后

复制代码 代码如下:

echo $_GET['jsoncallback'] . "(" . json_encode($res) . ")";

在AppCan的模版中,先加入一个下拉菜单,我的菜单是:

<!--下拉列表开始-->
<div class=" ui-has-label">
  <label class="ui-select ">选择楼群:</label>
  <div class="ui-select">
    <div class="ui-btn 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">楼名</span>
        <div class="ui-li-link-alt ui-btn ui-btn-corner-right ui-shadow">
        <span class="ui-icon 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)">
        数据加载中,请稍候
      </select>
    </div>
  </div>
</div>
<!--下拉列表结束-->
Copy after login

然后在中加入:

function getlq(){
  $.getJSON('http://localhost/json.php&#63;jsoncallback=&#63;', function(data) {
    var tmpl='<option value="${BuildingId}">${BuildingName}</option>';
    $("#lc").html("");
    $("#lc").append(zy_tmpl(tmpl,data,zy_tmpl_count(data)));
  })
}
Copy after login

这样在onload或者onchange、onclick时执行getlq();就能实现select的更新。

以上所述就是本文的全部内容了,希望大家能够喜欢。

请您花一点时间将文章分享给您的朋友或者留下评论。我们将会由衷感谢您的支持!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to make drop-down menu in WPS table How to make drop-down menu in WPS table Mar 21, 2024 pm 01:31 PM

How to make the WPS table drop-down menu: After selecting the cell where you want to set the drop-down menu, click &quot;Data&quot;, &quot;Validity&quot; in sequence, and then make the corresponding settings in the pop-up dialog box to pull down our menu. As a powerful office software, WPS has the ability to edit documents, statistical data tables, etc., which provides a lot of convenience for many people who need to deal with text, data, etc. In order to skillfully use WPS software to provide us with a lot of convenience, we need to be able to master various very basic operations of WPS software. In this article, the editor will share with you how to use WPS software. Perform drop-down menu operations in the WPS table that appears. After opening the WPS form, first select the

Performance optimization tips for converting PHP arrays to JSON Performance optimization tips for converting PHP arrays to JSON May 04, 2024 pm 06:15 PM

Performance optimization methods for converting PHP arrays to JSON include: using JSON extensions and the json_encode() function; adding the JSON_UNESCAPED_UNICODE option to avoid character escaping; using buffers to improve loop encoding performance; caching JSON encoding results; and considering using a third-party JSON encoding library.

How do annotations in the Jackson library control JSON serialization and deserialization? How do annotations in the Jackson library control JSON serialization and deserialization? May 06, 2024 pm 10:09 PM

Annotations in the Jackson library control JSON serialization and deserialization: Serialization: @JsonIgnore: Ignore the property @JsonProperty: Specify the name @JsonGetter: Use the get method @JsonSetter: Use the set method Deserialization: @JsonIgnoreProperties: Ignore the property @ JsonProperty: Specify name @JsonCreator: Use constructor @JsonDeserialize: Custom logic

In-depth understanding of PHP: Implementation method of converting JSON Unicode to Chinese In-depth understanding of PHP: Implementation method of converting JSON Unicode to Chinese Mar 05, 2024 pm 02:48 PM

In-depth understanding of PHP: Implementation method of converting JSONUnicode to Chinese During development, we often encounter situations where we need to process JSON data, and Unicode encoding in JSON will cause us some problems in some scenarios, especially when Unicode needs to be converted When encoding is converted to Chinese characters. In PHP, there are some methods that can help us achieve this conversion process. A common method will be introduced below and specific code examples will be provided. First, let us first understand the Un in JSON

How to set up excel drop-down menu to automatically associate data? Excel drop-down menu automatically associates data settings How to set up excel drop-down menu to automatically associate data? Excel drop-down menu automatically associates data settings Mar 13, 2024 pm 03:04 PM

How to set up Excel drop-down menu to automatically associate data? When we use excel, we use drop-down menus to quickly operate our data. However, many users also ask how to set up the drop-down menu to automatically associate data? Let this site introduce to users in detail how to set up automatic data association for excel drop-down menus. How to set up excel drop-down menu to automatically associate data 1. Open the Excel table. 2. Enter a piece of related data in a blank cell. 3. Then select the cells where you want to add a drop-down list. 4. Click [Data]-[Data Verification] on the menu bar. 5. Select [Sequence] for verification conditions. 6. Click the button pointed by the arrow in the picture and select

How to tell if a jQuery element has a specific attribute? How to tell if a jQuery element has a specific attribute? Feb 29, 2024 am 09:03 AM

How to tell if a jQuery element has a specific attribute? When using jQuery to operate DOM elements, you often encounter situations where you need to determine whether an element has a specific attribute. In this case, we can easily implement this function with the help of the methods provided by jQuery. The following will introduce two commonly used methods to determine whether a jQuery element has specific attributes, and attach specific code examples. Method 1: Use the attr() method and typeof operator // to determine whether the element has a specific attribute

PHP Tutorial: How to Convert JSON Unicode to Chinese Characters PHP Tutorial: How to Convert JSON Unicode to Chinese Characters Mar 05, 2024 pm 06:36 PM

JSON (JavaScriptObjectNotation) is a lightweight data exchange format commonly used for data exchange between web applications. When processing JSON data, we often encounter Unicode-encoded Chinese characters (such as "u4e2du6587") and need to convert them into readable Chinese characters. In PHP, we can achieve this conversion through some simple methods. Next, we will detail how to convert JSONUnico

Quick tips for converting PHP arrays to JSON Quick tips for converting PHP arrays to JSON May 03, 2024 pm 06:33 PM

PHP arrays can be converted to JSON strings through the json_encode() function (for example: $json=json_encode($array);), and conversely, the json_decode() function can be used to convert from JSON to arrays ($array=json_decode($json);) . Other tips include avoiding deep conversions, specifying custom options, and using third-party libraries.

See all articles