欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

AngularJS實(shí)現(xiàn)多級(jí)下拉框

 更新時(shí)間:2022年03月25日 16:44:39   作者:Lulus  
這篇文章主要為大家詳細(xì)介紹了AngularJS實(shí)現(xiàn)多級(jí)下拉框,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了AngularJS實(shí)現(xiàn)多級(jí)下拉框的具體代碼,供大家參考,具體內(nèi)容如下

<div ng-app="MultiDropDownApp" ng-controller="MultiDropDownControl as vm">
? ? <label>選擇地址:</label>
? ? <!--ng-options加載所有選擇項(xiàng),ng-model記錄當(dāng)前選擇項(xiàng)-->
? ? <select ng-model="vm.province" ng-options="x.name for x in vm.provinceSort"
? ? ? ? ? ? ng-change="vm.selectProvince()" id="" value="" class="form-control width-25">
? ? ? ? <option value="">請(qǐng)選擇</option>

? ? </select>
? ? <label>—</label>
? ? <select ng-model="vm.city" ng-options="x.name for x in vm.citySort"
? ? ? ? ? ? id="" value="" class="form-control width-25">
? ? ? ? <option value="">請(qǐng)選擇</option>

? ? </select>
</div>
<script src="~/Scripts/angular.min.js"></script>
<script>
? ? var app = angular.module('MultiDropDownApp', []);
? ? //可以添加上自己注入的服務(wù)
? ? app.controller('MultiDropDownControl', ['$scope', '$http',
? ? ? ? function ($scope, $http) {
? ? ? ? ? ? var vm = this;
? ? ? ? ? ? vm.provinceSort = [];
? ? ? ? ? ? vm.citySort = [];

? ? ? ? ? ? //選擇省級(jí)單位,初始化市級(jí)數(shù)據(jù) ? 二級(jí)聯(lián)動(dòng)
? ? ? ? ? ? vm.selectProvince = function () {
? ? ? ? ? ? ? ? var fatherID = vm.province.id;
? ? ? ? ? ? ? ? vm.citySort = [];
? ? ? ? ? ? ? ? $http({
? ? ? ? ? ? ? ? ? ? method: 'POST',
? ? ? ? ? ? ? ? ? ? url: '/AngularjsStudy/GetChildrenSort',
? ? ? ? ? ? ? ? ? ? data: { fatherID: fatherID }
? ? ? ? ? ? ? ? }).then(function successCallback(data) {
? ? ? ? ? ? ? ? ? ? vm.citySort = data.data;
? ? ? ? ? ? ? ? }, function errorCallback(response) {
? ? ? ? ? ? ? ? ? ? // 請(qǐng)求失敗執(zhí)行代碼
? ? ? ? ? ? ? ? });
? ? ? ? ? ? }

? ? ? ? ? ? //初始化頁(yè)面
? ? ? ? ? ? function init() {
? ? ? ? ? ? ? ? //省
? ? ? ? ? ? ? ? $http({
? ? ? ? ? ? ? ? ? ? method: 'POST',
? ? ? ? ? ? ? ? ? ? url: '/AngularjsStudy/GetProvinceSort',
? ? ? ? ? ? ? ? ? ? data: {}
? ? ? ? ? ? ? ? }).then(function successCallback(data) {
? ? ? ? ? ? ? ? ? ? //加載下拉框數(shù)據(jù)
? ? ? ? ? ? ? ? ? ? vm.provinceSort = data.data;
? ? ? ? ? ? ? ? ? ? //設(shè)置默認(rèn)選項(xiàng)
? ? ? ? ? ? ? ? ? ? vm.province = vm.provinceSort[0];
? ? ? ? ? ? ? ? }, function errorCallback(response) {
? ? ? ? ? ? ? ? ? ? // 請(qǐng)求失敗執(zhí)行代碼
? ? ? ? ? ? ? ? });
? ? ? ? ? ? }

? ? ? ? ? ? //初始化
? ? ? ? ? ? init();
? ? ? ? }])
</script>

Controller

public ActionResult GetProvinceSort()
? ? ? ? {
? ? ? ? ? ? List<District> districts = new List<District>();
? ? ? ? ? ? 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<District> districts = new List<District>();
? ? ? ? ? ? switch (fatherID)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? case 1:
? ? ? ? ? ? ? ? ? ? districts.Add(new District() { id = 4, fatherID = 1, name = "長(zhǎng)沙市" });
? ? ? ? ? ? ? ? ? ? districts.Add(new District() { id = 5, fatherID = 1, name = "岳陽(yáng)市" });
? ? ? ? ? ? ? ? ? ? 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 = "綿陽(yáng)市" });
? ? ? ? ? ? ? ? ? ? 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; }
? ? /// <summary>
? ? /// 根節(jié)點(diǎn)FatherID=0
? ? /// </summary>
? ? public int fatherID { get; set; }
? ? public string name { get; set; }
}

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論