【发布时间】:2017-03-22 09:11:44
【问题描述】:
我有这个数组对象:
$scope.datas.labels=['10','20','30']
而且我还有一个函数返回一个这样的数组对象:
response.labels=['10','20','30','50','100','80']
我创建了一个接收最后结果的函数..但我想要检查 response.labels 中的值是否存在于 $scope.datas.labels 我不想插入它..以避免重复数据$scope.datas.labels,我该怎么做??
我试过了,但没用:
$scope.concatToData=function (response) {
if($scope.datas.labels=='') {
$scope.datas.labels = $scope.datas.labels.concat(response.labels);
}else {
var i;
for (i = 0; i < $scope.datas.labels.length; i++) {
alert('qa' + JSON.stringify($scope.datas.labels));
alert('res' + JSON.stringify(response.labels));
if ($scope.datas.labels[i] !== response.labels[i]) {
$scope.datas.labels = $scope.datas.labels.concat(response.labels[i]);
} else {
break;
}
}
}
$scope.datas.datasets = $scope.datas.datasets.concat(response.datasets);
}
【问题讨论】: