正在更新Javascript对象值null
我试图通过在每次访问该页面时增加值来在页面上添加“视图”编号。通过AngularJS的 '一()'正在更新Javascript对象值null
{ _id: "55da051afe08e73168fc7aeb",
url: "https://www.youtube.com/watch?v=eUdM9vrCbow",
title: "Django Unchained",
embedUrl: "https://www.youtube.com/embed/eUdM9vrCbow",
__v: 0,
downvotes: 0,
upvotes: 0,
views: 0,
created_on: "2015-08-24T13:37:33.951Z",
desc: "With the help of his mentor, a slave-turned-bounty hunter sets out to rescue his wife from a brutal Mississippi plantation owner."
}
我检索此对象的方法:
我有这样的对象
var movie = Movie.one($routeParams.id);
我们的目标是增加该值。目前,我正在做这样的:
movie.views++; movie.put();
但是,这并不工作,只是给了我一个空值,而这样做的工作:
movie.views = 10; movie.put();
我在做什么错?
回答:
您无法增加null
的值,默认情况下将其设置为0(零)。
{ _id: "55da051afe08e73168fc7aeb",
url: "https://www.youtube.com/watch?v=eUdM9vrCbow",
title: "Django Unchained",
embedUrl: "https://www.youtube.com/embed/eUdM9vrCbow",
__v: 0,
downvotes: 0,
upvotes: 0,
views: 0, //instead of 'null'
created_on: "2015-08-24T13:37:33.951Z",
desc: "With the help of his mentor, a slave-turned-bounty hunter sets out to rescue his wife from a brutal Mississippi plantation owner."
}
回答:
我固定它是这样的:
我没有实际更新像Marc实际对象建议
Movie.one($routeParams.id).get().then(function(response){ response.views++;
$http.put("http://localhost:3000/movie/" + $routeParams.id, response);
});
以上是 正在更新Javascript对象值null 的全部内容, 来源链接: utcz.com/qa/260173.html