<! --Front-end Code section--
<Divclass= "Pop-movegroup"ID= "Salesmanbox"> <DL> <DT>Select a promotion account:</DT> <DD>
<!--first-level linkage data is queried and traversed.<Selectname= "Salesman"ID= "Salesman"> <volistname= "Salesman"ID= "Vo"> <optionvalue= "{$vo. ID}">{$vo. uname}</option> </volist> </Select><!--level Two linkage<Selectname= "Lib"ID= "Libs"> </Select> </DD> <DDclass= "Center"> <inputtype= "hidden"ID= ' uid 'value= "{$_get[' uid ']|intval}"> <inputtype= "button"class= "Btn_b mr10"value= "Confirm"onclick= "Admin.domovesalesuser ()"> <inputtype= "button"class= "Btn_w"value= "Cancel"onclick= "Ui.box.close ()"> </DD> </DL></Div>
JS section:
<Scripttype= "Text/javascript">
Click the option in the first level linkage to get the ID and then go to query the corresponding data
$("#salesman"). Change (function(){
Get IDvarCATID=$("#salesman"). val ();//submit ID to background $.post ("{: U (' Admin/user/doaddsalesusers ')}","id="+catid,function(data) {//Empty two-level linkage $ ("#libs"). empty (); //console.log (data); varCount=data.data.length; varI= 0; varb="";
Display the corresponding data according to the data returned by the backend for(i=0; I<Count;i++) {b+="<option value= '"+Data.data[i].uid+"' >"+Data.data[i].uname+"</option>"; } $("#libs"). Append (b); }); });//Click on the data in the level two menu Admin.domovesalesuser= function(){
Get IDvarID= $('#libs'). Val (); if(!ID) {Ui.error ('no Promotion account selected' );return false; }
To start bindingvarUID= $('#uid'). Val (); $.post (U ('Admin/user/doaddsalesuser'), {uid:uid,sid:id},function(msg) {ajaxreload (msg); //location.href = U (' Admin/user/index '); },'JSON'); }; </Script>
Back-End Code section:
Public functiondoaddsalesusers () {$id=$_post[' ID ']; $data= Model ("salesmanentity")->where ("sid =").$id),Select (); $this->ajaxreturn ($data, "JSON"); } Public functionDoaddsalesuser () {$return=Array(' status ' = ' 0 ', ' data ' = ' Bind promotion account failed '); $uid= !Empty($_post[' UID '])?intval($_post[' UID ']) : 0;//Yonghuid//Var_dump ($UID); $sid= !Empty($_post[' Sid '])?intval($_post[' Sid ']) : 0;//suoshuzuid//var_dump ($SID); Var_dump ($dataArray); if(Empty($uid) ||Empty($sid)){ $return[' data '] = "Invalid!" "; Exit(Json_encode ($return)); } //go to the Salesman_entity table to query the user group that the female ID belongs to $dataArray= M (' salesman_entity ')->where ("uid=").$_post[' Sid ']) ->field ("Sid")Select (); //Var_dump ($dataArray); $idss= Array_column ($dataArray, ' Sid '); //invite_id $yqId=$idss[0]; //Female User ID $user= Model (' User ')->where (' uid= ').$uid),find (); if($user[' invite_id ']>0){ $this->error ("The user has been bound! "); } $datas=Array(' invite_id ' =$yqId, ' sid ' =$sid); //Start Binding if(The model (' User ')->where (' uid= ').$uid)->setfield (' invite_id ',$yqId) && model (' User ')->where (' uid= ').$uid)->setfield (' Sid ',$sid)){ $return=Array(' status ' = 1, ' data ' = ' user bindings succeeded '); } Exit(Json_encode ($return)); }
Thinkphp Two-level linkage