Thinkphp2.1 template use notes-template nesting/ajax Cascade

Source: Internet
Author: User
Recently, PHP has been used in projects, but it is not very familiar with framework development. It is well known in the process and recorded for future reference.

  Label library select label usage <Taglib name = "html"/> <HTML: Select Options = "productcategory"
Selected = "prodcateid" first = "select category" name = "prod_cate_id" id = "prod_cate_id"
/> $ Cate
= D ('productcategory '); $ list
= $ Cate-> Field ('prod _ cate_id, prod_cate_name ')-> findall (); foreach ($ list as $ vo) {$ grouplist [$ VO ['prod _ cate_id '] = $ VO ['prod _ cate_name'];} $ this-> assign ('productcategory ', $ grouplist ); $ this-> assign ('prodcateid', ''); $ this-> display ('edit '); <Volist> label nesting  <Volist name = "list" id = "VO">

{$ VO. prod_cate_name} <volist name = "VO ['voo']"
Id = "sub" >{$ sub. prod_cate_name} </volist>

</Volist> $ Dao
= M ('productcategory '); $ list
= $ Dao-> where ('ifnull (prod_cate_pid, 0) = 0')-> Order ('prod _ cate_order ASC ')-> findall (); $ sub
= M ('productcategory '); foreach ($ list as $ n => $ Val) {$ list [$ N] ['voo'] = $ sub-> where ('prod _ cate_pid = '. $ Val ['prod _ cate_id '])-> select () ;}$ this-> assign ('LIST', $ list );

$ This-> display ();Implementation of Ajax second-level linkage <SCRIPT type = "text/JavaScript"
Src = "_ root _/public/scripts/jquery-1.7.1.min.js"> </SCRIPT>

<SCRIPT type = "text/JavaScript"> function ajaxselect (URL, objone, objtwo, defval ){

VaR $ S1 = $ (objone); var $ S2 = $ (objtwo); $ s1.change (function () {var curval = objone. options [objone. selectedindex]. value; $s2.html (""); $ ("<option> "). text ("secondary Classification "). val (""). appendto ($ S2); $. ajax ({type: "Post", URL: URL, data: "catepid =" + curval, datatype: 'json', success: function (OBJ) {If (obj. data) {$ (eval (obj. data )). each (function (I, elm) {appendoptionto ($ S2, Elm. prod_cate_name, Elm. prod_cate_id, defval );});}}});}). change (); function appendoptionto (O, K, V, d) {var opt = $ ("<option> "). text (k ). val (V); If (V = d) {OPT. ATTR ("selected", "selected")} OPT. appendto (o) ;}}$ (function () {ajaxselect ('_ URL _/changecategory', $ ('# cate_one '). get (0), $ ('# cate_two '). get (0), '{$ vo. cate_two }');


});

</SCRIPT> <taglib name = "html"/>

<HTML: Select Options = "productcategory"
Selected = "prodcateid" first = "select category" name = "cate_one" id = "cate_one"/>

<Select name = "cate_two" id = "cate_two"> <option value = ""> secondary classification </option> </SELECT>

Public Function
Changecategory () {$ id = $ _ post ['catepid']; header ("Content-Type: text/html;
Charset = UTF-8 "); $ Cate
= D ('productcategory '); $ list
= $ Cate-> Field ('prod _ cate_id, prod_cate_name ')-> where ('prod _ cate_pid = '. $ id)-> select (); $ this-> ajaxreturn (json_encode ($ list), '','', 0 );

}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.