Angularjs - 将对象推送或取消移动到数组的正确方法是什么?

时间:2016-03-02 15:40:10

标签: arrays angularjs

我从后端获取数组值。在这个后端数组中,我添加了一个新值,其中一些属性来自后端数组值之一。在我unshift这个值之后,我正在安慰它。当我安慰它时,它与我在highlightexpanded中看到的不同。

这是截图:

查看属性PhaseName,当您展开时,All会显示$scope.project = project; var staticPhase = { //custom properties "DisciplineId": "0", "DisciplineName": "All", "PhaseId": "0", "PhaseName": "All" } var filterById = angular.copy( $filter('filter')($scope.project.ProjectSummaryFilter, { ProjectId : $scope.projectId })[0] ); //getting some of property from server object and assigning;- staticPhase.ProjectId = filterById.ProjectId; staticPhase.ProjectName = filterById.ProjectName; staticPhase.SubProjectId = filterById.SubProjectId; staticPhase.SubProjectName = filterById.SubProjectName; $scope.project.ProjectSummaryFilter.unshift(staticPhase);

这是什么问题?怎么解决?

enter image description here

这是我的代码:

df <- read.csv(textConnection(gsub("\\.+", ",", 
  "1...... 2...... 3..... 4..... 5
  1...... 3...... 5..... 4..... 5
  4...... 2...... 1..... 1..... 2
  1...... 2...... 3..... 4..... 5
  3...... 3...... 4..... 2..... 1")), header=FALSE)

apply(df, 2, function(x)x[1]==x)
        V1    V2    V3    V4    V5
[1,]  TRUE  TRUE  TRUE  TRUE  TRUE
[2,]  TRUE FALSE FALSE  TRUE  TRUE
[3,] FALSE  TRUE FALSE FALSE FALSE
[4,]  TRUE  TRUE  TRUE  TRUE  TRUE
[5,] FALSE FALSE FALSE FALSE FALSE

1 个答案:

答案 0 :(得分:1)

我建议您使用功能https://lodash.com/docs#remove

的lodash
Or use can use the angular.forEach(function(val,index){
//then slice this here
});