商品分类 - 三级分类
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>