ng-repeat를 사용하여 목록 내부에 데이터를 채 웁니다.AngularJs : 배열 푸시가 다른 요소를 대체합니다.
HTML - 후 임시 변수를 만들어 형태에서의 값을 저장
<div ng-repeat="data in GCAList|filter:year" class="listGCA" ng-click="select()">
<div class="listLibraryName">
{{ data.LibraryName }}
</div>
<div class="listProjects">
{{ data.Projects }}
</div>
<div class="listStatus">
{{ data.Status }}
</div>
<div class="listYear">
{{data.TaxYear}}
</div>
</div>
배열로 밀어. 이제 푸쉬하는 동안 문제는 $$ hashkey : "object : 81"이 자동으로 생성되고 다음 푸시를 위해 동일한 해시 키가 생성되고 배열에 이전에 삽입 된 데이터를 대체합니다.
스크립트 파일을 교체하는 일이 없도록 도움이되지 않았다 $ 지수에 의해 트랙 추가
ng-repeat="data in GCAList|filter:year track by $index"
: 난에 '$ 인덱스 트랙'을 사용 당신은을 사용하기 때문에
var app = angular.module("Accounts", ['restangular', 'ngDialog', 'ngAnimate'])
var temp = {
"id": 0,
"LibraryName": "" ,
"Projects": 0,
"Status": "",
"TaxYear": 0
};
app.controller("accountsController", function($scope, ngDialog, RestRepository) {
$scope.showEGCA = false;
$scope.showGCA = true;
$scope.name = "";
RestRepository.getJson().then(function(response) {
$scope.dataList = response;
console.log($scope.dataList);
$scope.GCAList = $scope.dataList[0];
console.log($scope.GCAList);
$scope.EGCAList = $scope.dataList[1];
console.log($scope.EGCAList);
});
$scope.popOpen = function() {
ngDialog.open({
template: 'Pop Up.html',
scope: $scope,
controller: function($scope) {
$scope.cancelCOA = function() {
ngDialog.close();
};
$scope.createGCA = function() {
temp.id = $scope.GCAList.length + 1;
temp.LibraryName = $scope.name;
temp.Projects = 2;
temp.Status = "Inactive";
temp.TaxYear = $scope.taxYear;
console.log(temp);
$scope.GCAList.push(temp);
console.log($scope.GCAList);
ngDialog.close();
};
},
closeByDocument: false,
closeByEscape: false,
showClose: false,
});
};
$scope.gcaOpen = function() {
$scope.showGCA = !$scope.showGCA;
$scope.showEGCA = true;
};
$scope.egcaOpen = function() {
$scope.showEGCA = !$scope.showEGCA;
$scope.showGCA = true;
};
});
app.config(function(RestangularProvider) {
RestangularProvider.setBaseUrl('http://10.198.50.19:98/jsonData/');
});
app.factory("RestRepository", [
'Restangular', function(Restangular) {
return {
getJson: function() {
return Restangular.one('jsonData.json').get();
}
}
}
]);
'temp' 모든 푸시를위한 새로운 객체 여야합니다 : 당신이 동일한 개체 속성을 변경하고 배열에 아이디어 @fantarama에 대한 – fantarama
감사를 동일한 인스턴스를 추가! :) 그것은 일했다 .. –