AngularJS实现多级下拉框

本文实例为大家分享了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; }
}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

你可能感兴趣的:(AngularJS实现多级下拉框)