Table structure Second-level or multi-level linkage is mainly based on the table with parent number in the database, and this is no exception Three columns of id, parent_id, name.
Using js operation Let’s first talk about how data is stored in js. Mainly use two-dimensional arrays to store data. The structure is as follows: a[parent number]=[[child number 1, child name 1], [child number 2, child name 2], [child number 3, child name 3],…]; First, use the parent number to get all the child data, and then bind the number and name of the child data in dropdown
The first step is the second-level linkage data (how to get these data later)
//Get the corresponding child data based on the parent number and display it in the obj control //type=0 city, 1 school //pid parent number //obj to Dropdown to display data function SetRegions(type,pid,obj) { var text="
In the third step, when the city changes, select school data
//Initialize city school value //cityId city number //schoolId school number function InitRegions(cityId,schoolId) { //Initialize city data //SetRegions(0,"00000000-0000-0000-0000-000000000000","#cities"); //Find the city and set it as the default value $("#cities option[value =" cityId "]").attr("selected","selected"); if(schoolId!="00000000-0000-0000-0000-000000000001"){ //Initialize school data SetRegions(1,cityId,"#schools"); //Find a school and set it as the default value $("#schools option[value=" schoolId "]").attr("selected", "selected"); } }
/// /// 지역 js 파일 생성 /// private void CreateRegions() { #region Get 지역 파일 정보 string _cities = "var 도시=new Array(); " string _schools = "varschools=new Array(); "; 🎜>DAL.RegionInfo dalRegion = new DAL.RegionInfo(); #region 도시 정보 DataTable dtcity = dalRegion.GetList("parent_id='" "00000000-0000-0000-0000-000000000000" "'" ).Tables[0]; _cities = "cities ['" ParentId "']=["; foreach(dtcity.Rows의 DataRow c) { _cities = "['" c["id"].ToString() "',' " c["name"].ToString() "'],"; #지역 학교 정보 DataTable dtschool = dalRegion.GetList(" parent_id ='" c["id"] "'"). 테이블[0]; if (dtschool == null || dtschool.Rows.Count == 0) { 계속; } _schools = "schools['" c[ "id"].ToString() "']=[" foreach(dtschool.Rows의 DataRow s) { _schools = "['" s["id"].ToString() "','" s["name"].ToString() "']," } _schools = _schools.TrimEnd(', ') "]; "; #endregion } _cities = _cities.TrimEnd(',') "]; " # endregion Response.Write(_cities "
") Response.Write(_schools "
"); 🎜>#endregion }
페이지에서 출력되는 js 링크 데이터를 js 파일에 직접 복사 3레벨 또는 다레벨로 변경할 수도 있습니다. 자신의 필요에 따라 연결하는 것도 같은 원리입니다. 모두에게 도움이 되길 바랍니다
Statement:
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