我创建了一个用于显示问题here
的plunker如果您点击"显示缺少数据的行"链接然后一切都很好,它过滤显示行与错误的数据。但是,如果您再点击"显示所有数据"它不会再显示其余数据?如何解决这个问题?
代码:
vm.applyMissingValuesFilter = function (linktext) {
if (linktext === "Display rows with missing data") {
vm.savedResourceGridResources = vm.resourceGridResources;
var results = [];
var temp = vm.resourceGridResources.Resources;
for (var i = 0; i < temp.length; i++) {
for (var j = 0; j < temp[i].Resources.length; j++) {
if (!temp[i].Resources[j].Value) {
if (results.indexOf(temp[i]) === -1) {
results.push(temp[i]);
}
}
}
}
vm.resourceGridResources.Resources = results;
vm.missingValuesButtonText = "Show all data";
}
else if (linktext === "Show all data") {
// should reset the resource values here to redisplay original data?
vm.resourceGridResources = vm.savedResourceGridResources;
vm.missingValuesButtonText = "Display rows with missing data";
}
};
答案 0 :(得分:3)
在修改数据之前,您必须使用angular.copy
来保存数据:
vm.savedResourceGridResources = angular.copy(vm.resourceGridResources);