• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

正在更新Javascript对象值null

JavaScript 来源:Roemerdt 3次浏览

我试图通过在每次访问该页面时增加值来在页面上添加“视图”编号。通过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." 
} 

版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)