无法动态更新新值并更改ui-select中的选定值 更新的值在列表中重复
我添加了让员工更新模型并更新员工以添加新数据并预先选择该值。
我所做的是
问题是第4项被选中,但它也会显示在选择列表中
下面给出的plunkr链接 http://plnkr.co/edit/RCEQeSp00QhnLl4wegpz?p=preview
<ui-select style="width: 800px;" ng-disabled="disabled" theme="select2" ng-model="vm.employees.selected" multiple="">
<ui-select-match placeholder="Select employee...">{{$item.name}} <{{$item.city}}></ui-select-match>
<ui-select-choices refresh-delay="0" refresh="vm.getdata($select.search)" repeat="employee.id as employee in vm.employees | propsFilter: {name: $select.search} ">
<div ng-bind-html="employee.name | highlight: $select.search"></div>
<small>
name: {{employee.name}}
city: <span ng-bind-html="''+employee.city | highlight: $select.search"></span>
</small>
</ui-select-choices>
</ui-select>
app.controller('DemoCtrl', function($http) {
var vm = this;
vm.name = 'World';
function getemployee() {
var employees = [];
$http.get('employees.json').success(function(data) {
vm.employees = data;
});
}
vm.updateemployee = function() {
console.log(vm.employees);
vm.selvalues = vm.employees.selected;
vm.employees.selected = undefined;
vm.employees.push({
id: 9,
name: "test",
city: "chennai",
state: "TN"
});
vm.selvalues.push(9);
vm.employees.selected = vm.selvalues;
console.log(vm.employees);
console.log(vm.employees.selected);
}
vm.getdata = function(query) {
console.log(vm.employees);
console.log(vm.employees.selected);
}
vm.employees = {};
vm.selvalues = [];
vm.employees.selected = [];
vm.employees = [];
vm.getemployee = getemployee;});
[plunkr link] [1]
答案 0 :(得分:1)
vm.selvalues= vm.employees.selected;
vm.employees.selected=undefined;
vm.employees=vm.employees.concat({id:9,name:"test",city:"chennai",state:"TN"});
vm.employees.selected = vm.selvalues.concat(9);
改变对concat的推动对我有用。 感谢所有试图帮助我的人