千家信息网

AngularJS怎么实现多级下拉框

发表于:2024-11-11 作者:千家信息网编辑
千家信息网最后更新 2024年11月11日,本篇内容主要讲解"AngularJS怎么实现多级下拉框",感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习"AngularJS怎么实现多级下拉框"吧!具体代码如下
千家信息网最后更新 2024年11月11日AngularJS怎么实现多级下拉框

本篇内容主要讲解"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怎么实现多级下拉框"有了更深的了解,不妨来实际操作一番吧!这里是网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!

0