【问题标题】:Meteor.js: what object does {$set: {...} } get?Meteor.js: {$set: {...} } 得到什么对象?
【发布时间】:2013-06-02 19:02:41
【问题描述】:

我的 Posts.update() 似乎有问题;方法。

    var postProperties = {
        url: $(e.target).find('[name=url]').val(),
        title: $(e.target).find('[name=title]').val()
    }

    Posts.update(currentPostId, {$set: postProperties}, function(error){
        if (error) {
            // display the error to the user
            alert(error.reason);
        }
        else {
            Meteor.Router.to('postPage', currentPostId);
        }
    });

currentPostId 可能没有错,因为 remove 工作正常:

Posts.remove(currentPostId);

所以 postProperties 对象必须是:

Object {url: "https://github.com/DiscoverMeteor/Microscope", title: "Random Title"} 

帖子有一个网址、一个标题和一条消息。我有一个消息的 .deny() 方法,所以我不会更新它。

任何关于我做错了什么的见解?

感谢您的宝贵时间。

【问题讨论】:

  • currentPostIdthis.currentPostId的值是多少?
  • this.currentPostId 为“未定义”,在本例中 currentPostId 为“wHtYDGjRgbWMYnzMy”。所以我不明白为什么 currentPostId 失败而 this.currentPostId 没有。
  • this.currentPostId 不会失败,因为没有要更新的记录。尝试使用Posts.update({_id: currentPostId}, ....)
  • 我仍然收到“内部服务器错误”。另外,_id = currentPostId 的帖子肯定存在。

标签: javascript meteor meteorite


【解决方案1】:

我看了看我的终端,所以有一个

Exception while invoking method '/posts/update' ReferenceError: alert is not defined

问题是忘记了 alert();在 Posts.deny();方法。从我现在警告的内容来看,它不是 Javascript 的一部分,而是 DOM(?) 的一部分。删除 alert() 后一切正常。

上面代码中的 alert() ( Posts.update(); ) 有效,因为它位于

Template.postEdit.events({...});

因此,处理 DOM 事件,其中 alert();工作得很好。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-11-11
    • 1970-01-01
    • 2017-02-17
    • 2022-12-09
    • 2020-08-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多