
<select ng-init="cheng=pros[0]"ng-model="cheng" ng-options="p.pro for p in pros" ng-change="gai(cheng)">
</select><select ng-init="shi=city[0]" ng-model="shi" ng-options="o for o in city">
</select>
<script>
var app= angular.module("myapp",[]);
app.controller("myctrl",function($scope,$http){
$http.get("http://result.eolinker.com/rR1VBtT56a6bb220c10b3d44b65b4787a8aec03c4ec32ce?uri=monthTest").then(function(response){
$scope.names=response.data;
});
//自己定义的二级数组(如果网络请求 将$scope.city=$scope.pros[0].child删除即可)
$scope.pros=[{"pro":"北京","child":["东城","西城","西二旗"]},{"pro":"河南","child":["郑州","洛阳","驻马店"]}];
//给city赋默认值
$scope.city=$scope.pros[0].child;
//二级联动改变事件
$scope.gai=function(sh){
$scope.city=sh.child;
}
</script>
这篇博客展示了如何在AngularJS中实现简单的二级联动效果。通过使用`ng-init`, `ng-model`, `ng-options` 和 `ng-change` 指令,创建了一个基于省份选择的城市下拉列表。示例中,当省份选择发生变化时,会更新对应城市的列表。数据源通过 `$http.get` 从API获取,同时提供了一个静态数据示例作为备用。"
101632655,8500964,递推求解母牛数量,"['算法', '数学', '编程挑战', '递归']
269

被折叠的 条评论
为什么被折叠?



