AngularJS 多级下拉框



Controller

        public ActionResult GetProvinceSort()
        {
            List districts = new List();
            districts.Add(new District() {id=1,fatherID=0,name="湖南省" });
            districts.Add(new District() { id =2, fatherID = 0, name = "湖北省" });
            districts.Add(new District() { id =3, fatherID = 0, name = "四川省" });
            return Json(districts);
        }

        public ActionResult GetChildrenSort(int fatherID)
        {
            List districts = new List();
            switch (fatherID)
            {
                case 1:
                    districts.Add(new District() { id = 4, fatherID = 1, name = "长沙市" });
                    districts.Add(new District() { id = 5, fatherID = 1, name = "岳阳市" });
                    districts.Add(new District() { id = 6, fatherID = 1, name = "株洲市" });
                    return Json(districts);
                case 2:
                    districts.Add(new District() { id = 7, fatherID = 2, name = "武汉市" });
                    districts.Add(new District() { id = 8, fatherID = 2, name = "宜昌市" });
                    return Json(districts);
                case 3:
                    districts.Add(new District() { id = 9, fatherID = 3, name = "成都市" });
                    districts.Add(new District() { id = 10, fatherID = 3, name = "遂宁市" });
                    districts.Add(new District() { id = 11, fatherID = 3, name = "巴中市" });
                    districts.Add(new District() { id = 12, fatherID = 3, name = "绵阳市" });
                    districts.Add(new District() { id = 13, fatherID = 3, name = "南充市" });
                    return Json(districts);
                default:
                    districts.Add(new District() { id = 14, fatherID = -1, name = "不知道你选了什么∑q|゚Д゚|p" });
                    return Json(districts);
            }
        }

Model

public class District
{
    public int id { get; set; }
    /// 
    /// 根节点FatherID=0
    /// 
    public int fatherID { get; set; }
    public string name { get; set; }
}

转载于:https://www.cnblogs.com/Lulus/p/7874113.html

你可能感兴趣的:(javascript,json)