【发布时间】:2015-01-28 13:30:40
【问题描述】:
我通过它的 id 有这样一个帖子的 json 表示:
http://127.0.0.1:8000/update/1?format=json
{"title": "about me", "content": "I like program", "created": "2014-11-29T18:07:18.173Z", "rating": 1, "id": 1}
我尝试通过点击按钮来更新评分:
<button ng-click="click(post.id)">Click me</button>
我有这样的javascript代码:
<script>
var demoApp = angular.module('demoApp',['ngResource']);
demoApp.controller( 'AllPosts', function ($scope, $http)
{
$http.get('/blogpost/?format=json').success(function(data,status,headers,config)
{
$scope.posts = data.results;
$scope.predicate = '-title';
$scope.click = function(post_id, $resource){
var Post = $resource('/update/:PostId ',{PostId:post_id,format:'json'} );
post = Post.get({PostId:post_id}, function() {
post.rating = post.rating+ 1 ;
post.$save();
});
};
}).error(function(data,status,headers,config)
{} )
;})
</script>
Peharps 我错了,因为在 json 中我只有一个对象。但我真的不知道
此外,我有这样的观点,即通过某个帖子的 id 获得一个 json:
class UpdateModel(generics.RetrieveUpdateDestroyAPIView):
lookup_field = 'id'
queryset = BlogPost.objects.all()
serializer_class = BlogPostSerializer
permission_classes = (AllowAny,)
【问题讨论】:
标签: javascript python json django angularjs