我尝试克隆我的响应json,但id是相同的..
我想在我的json中克隆一个项目以方便添加内容。 问题是遵循相同的ID,然后答案是更新,没有新项..
功能:
$scope.cloneItem = function(id) {
$scope.itemtoclone = allDB.get({section: section, id: id}, function(){
$scope.itemnew = new allDB({section: section});
$scope.itemnew = angular.copy($scope.itemtoclone);
$scope.itemnew.$save(function(){
$mdToast.show($mdToast.simple({position: 'top right'}).content('Clone criado!'));
});
});
}
和回复:
GET http://localhost:5000/posts/25 304 Not Modified 7ms
POST http://localhost:5000/25 201 Created 2ms
要克隆的json对象:
{
"id": 25,
"title": "Willian busca protagonismo igual ao de Neymar: \"Sempre joguei assim\"",
"subtitle": "Com 94% de aproveitamento nos passes na estreia da Copa América, jogador tem chamado a
responsabilidade e dividido a missão de criar os lances com o camisa 10",
"slug": "brasil-post-1",
"published": true,
"originalDate": "2015-06-16T03:00:00.000Z",
"excerpt": "Com 94% de aproveitamento nos passes na estreia da Copa América",
"$promise": {},
"$resolved": true,
"cats": [
2,
3,
4,
5,
7
]
}
解决了,这不是我想要的,但我帮忙!
$scope.cloneItem = function(id) {
$scope.getclone = allDB.get({section: section, id: id}, function(response){
console.log(response);
$scope.itemnew = new allDB({section: section});
$scope.itemnew.title = response.title;
$scope.itemnew.subtitle = response.subtitle;
$scope.itemnew.excerpt = response.excerpt;
$scope.itemnew.$save(function(){
$mdToast.show($mdToast.simple({position: 'top right'}).content('Clone criado!'));
});
});
}