我有两个列表,我连接它们没有重复值,我这样做,所以我有重复值,为什么..?
在我的HTML中
..
<list-of-items items="platforms.concat(platformsCible).unique()"
label="$item"
selected-item="platform"
createfunction="add_platform($name)"
selectable="true"
editable="false"
size="small">
</list-of-items>
..
在我的JS中
propertiesModule.controller('PropertiesCtrl', ['$scope', '$routeParams', 'PropertiesService', 'ApplicationService', 'PlatformService', 'Page', function ($scope, $routeParams, PropertiesService, ApplicationService, PlatformService, Page) {
...
$scope.platforms = [];
/* Find all the platforms */
PlatformService.get($routeParams.application, $routeParams.version).then(function(platforms){
$scope.platforms = platforms;
}).then(function(){
/* If platform was mentionned in the route, try to find it or add it */
if($scope.platform) $scope.add_platform($scope.platform);
});
/* Find all the platforms cible */
if( $routeParams.versionCible != null) {
PlatformService.get($routeParams.application, $routeParams.versionCible).then(function (platforms) {
$scope.platformsCible = platforms;
}).then(function () {
/* If platform was mentionned in the route, try to find it or add it */
if ($scope.platformCible) $scope.add_platform($scope.platformCible);
});
}
Array.prototype.unique = function() {
var a = this.concat();
for(var i=0; i<a.length; ++i) {
for(var j=i+1; j<a.length; ++j) {
if(a[i] === a[j])
a.splice(j--, 1);
}
}
return a;
};
}]);
答案 0 :(得分:0)
尝试使用原生角度工具:angular.extend(dst,src); 在你的情况下,它将是angular.extend(平台,平台可行)
它不会尝试深度比较对象,只会尝试它们的键值对,因此它可以帮助您获得独特平台的连续列表。