gpt4 book ai didi

javascript - 更新 Javascript 对象值给出 null

转载 作者:行者123 更新时间:2023-12-03 09:06:00 24 4
gpt4 key购买 nike

我正在尝试通过每次有人访问该页面时增加该值来在我的页面上添加“查看”数量。

我有一个像这样的对象:

{
_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."
}

我通过 AngularJS 的“.one()”方法检索该对象:

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."
}

关于javascript - 更新 Javascript 对象值给出 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32184203/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com