angularJS 实现三级联动

商品分类 - 三级分类
	id		pid		name				code
	1		0		手机				1
	2		0		电视				2
	3		1		手机壳  			1-3
	4		1		SD卡				1-4
	5		3		apple手机壳			1-3-5

三级联动
有三级分类,当确定第一级分类的时候,二级分类的可选择项目就要初始化。

	$scope.$watch("obj",function(a,b){
					if(!a){
						return;
					}
					// a 表示修改后的值。
					// b 表示修改前的值。
				});

controller代码:

// 一级显示列表
	$scope.selectItemCat1List = function() {

		itemCatService.findByParentId('0').success(function(response) {

			$scope.ItemCat1List = response;

		});
	}
	// 二级显示
	$scope.ItemCat2List = [];
	$scope.$watch("entity.goods.category1Id", function(newValue, oldValue) {
		itemCatService.findByParentId(newValue).success(function(response) {
			$scope.ItemCat2List = response;

		});

	});

	$scope.ItemCat3List = [];
	// 三级显示
	$scope.$watch("entity.goods.category2Id", function(newValue, oldValue) {
		itemCatService.findByParentId(newValue).success(function(response) {

			$scope.ItemCat3List = response;

		});

	});
	// 模板ID显示
	$scope.typeId = {};
	$scope.$watch("entity.goods.category3Id", function(newValue, oldValue) {
		itemCatService.findOne(newValue).success(function(response) {

			$scope.entity.goods.typeTemplateId = response.typeId;

		});
	});

前台三级显示:

	<table>
	<tr>
			<td>
			<!-- 一级显示 -->
			<select class="form-control" 
			ng-options="item.id as item.name for item in ItemCat1List"
			ng-model="entity.goods.category1Id">
			</select>
			</td>
			<td>
			<!-- 二级显示 -->
			<select class="form-control"
			ng-options="item.id as item.name for item in ItemCat2List"
			ng-model="entity.goods.category2Id">
			</select>
			</td>
			<td>
			<!-- 三级显示 -->
			<select class="form-control"
			ng-options="item.id as item.name for item in ItemCat3List"
			ng-model="entity.goods.category3Id">
			</select>
			</td>
			<td>模板ID:{{entity.goods.typeTemplateId }}</td>
		</tr>
	</table>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值