当我按下编辑按钮时,为什么Group-Row为空? 我想从列表中获得相同的值,当编辑模式打开时,下拉列表可见。
我该如何解决这个问题?
请查看此工作代码:
这是我的plnkr
var app = angular.module("employment", ["xeditable"]);
app.run(function(editableOptions) {
editableOptions.theme = 'bs3'; // bootstrap3 theme. Can be also 'bs2', 'default'
});
app.controller('EditableRowCtrl', function($scope, $filter, $http)
{
$scope.users = [];
$http.get('userdata.json').success(function(data){
$scope.users = data;
});
$scope.statuses = [
{value: 1, text: 'aktiv'},
{value: 2, text: 'inaktiv'}
];
$scope.groups = [
{id: 1, text: 'Administrator'},
{id: 2, text: 'SuperUSer'},
{id: 3, text: 'Mitglied'},
];
$scope.showGroup = function(user) {
if(user.group && $scope.groups.length) {
var selected = $filter('filter')($scope.groups, {id: user.group});
return selected.length ? selected[0].text : 'Not set';
} else {
return user.groupName || 'Not set';
}
};
$scope.showStatus = function(user) {
var selected = [];
if(user.status) {
selected = $filter('filter')($scope.statuses, {value: user.status});
}
return selected.length ? selected[0].text : 'Not set';
};
// remove user
$scope.removeUser = function(index) {
$scope.users.splice(index, 1);
};
// add user
$scope.addUser = function() {
$scope.inserted = {
id: $scope.users.length+1,
name: '',
status: null,
group: null
};
$scope.users.push($scope.inserted);
};
});

答案 0 :(得分:1)
@ M1ke,我不知道你是否还在努力。我刚看到这个问题。问题是您的状态和组代码在userdata.json中定义为字符串,在状态和组对象中定义为整数。我只是将它们更改为userdata中的整数,它就像一个魅力。