AngularJS-xeditable 下拉框使用以及踩的坑
原主题版
html
{{ showGroup(user) }}
js
$scope.users = [ {id: 1, name: 'awesome user1', status: 2, group: 4, groupName: 'admin'}, {id: 2, name: 'awesome user2', status: undefined, group: 3, groupName: 'vip'}, {id: 3, name: 'awesome user3', status: 2, group: null} ]; $scope.groups = []; $scope.loadGroups = function() { return $scope.groups.length ? null : $http.get('api/groups').success(function(data) {//获取后台数据 $scope.groups = data; }); }; $scope.showGroup = function(user) {/ if(user.group && $scope.groups.length) { var selected = $filter('filter')($scope.groups, {id: user.group});//将值赋值给id,然后编辑下拉框时 显示 selected[0].text的值 return selected.length ? selected[0].text : 'Not set'; } else { return user.groupName || 'Not set'; } };
json
[ {"id": 1, "text": "user"}, {"id": 2, "text": "member"}, {"id": 3, "text": "vip"}, {"id": 4, "text": "admin"} ]
所用项目修改版
html
{{ showcompanyGroup(item) }}
js
$scope.companygroups = [] $scope.loadcompanyGroups = function() { return $scope.companygroups.length ? null : $http.get('/jsjxyxt/unit/get.do').success(function(data) { $scope.companygroups = data.result; }); }; $scope.showcompanyGroup = function(item) { if(item.unit.uname && $scope.companygroups.length) { var selected = $filter('filter')($scope.companygroups, {uname: item.unit.uname}) return selected.length ? selected[0].uname : ' '; }else{ return item.unit.uname || ' '; } };
然后今晚遇上了坑,点击编辑的时候下拉框的默认值为空,找了好久没有发现原因,最后才发现,从后台传来的json中没有编辑前的那个值,所以下拉框默认为空