栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

在AngularJS中切换数据模型以获取动态选择菜单

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

在AngularJS中切换数据模型以获取动态选择菜单

看看我在这里做了什么:http :
//jsfiddle.net/sgdea/2/

您根本不需要使用

$watch
-您只需要使每个从属选择的输入引用父项中的选择即可。

请注意

ng-options
第二个和第三个选择引用的
selected.site
,这是由第一个选择设置的:

<div ng-app="myApp" ng-controller="BookingCtrl">    <select ng-model="selected.site" ng-options="s.site for s in data">        <option value="">-- Site --</option>    </select>    <select ng-model="selected.building" ng-options="b.building for b in selected.site.buildings">        <option value="">-- Building --</option>    </select>    <select ng-model="selected.floor" ng-options="f.floor for f in selected.site.floors">        <option value="">-- Floor --</option>    </select></div>

我在javascript中所做的只是删除了您的

$watch

var myApp = angular.module( 'myApp', [] );myApp.controller( 'BookingCtrl', ['$scope', '$location', function ( $scope, $location ) {    $scope.selected = {};    $scope.data = [        { "id" : "0", "site" : "Brands Hatch", "buildings" : [     { "building" : "Building #1" },     { "building" : "Building #2" },     { "building" : "Building #3" } ], "floors" : [     { "floor" : "Floor #1" },     { "floor" : "Floor #2" },     { "floor" : "Floor #3" } ]        },{ "id" : "1", "site" : "Silverstone", "buildings" : [     { "building" : "Building #4" },     { "building" : "Building #5" },     { "building" : "Building #6" } ], "floors" : [     { "floor" : "Floor #4" },     { "floor" : "Floor #5" },     { "floor" : "Floor #6" } ]        }    ];}]);


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/483213.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号