2013-06-01 21 views
0

我的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可能是沒有過錯的,因爲刪除工作得很好:

Posts.remove(currentPostId); 

所以postProperties對象必須是:

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

帖子有一個URL,標題和信息。我有一個.deny()方法的消息,所以我沒有更新。

任何洞察我做錯了什麼?

謝謝你的時間。

+0

'currentPostId'和'this.currentPostId'的值是什麼? – Xyand

+0

this.currentPostId是'未定義的',currentPostId在這種情況下是'wHtYDGjRgbWMYnzMy'。所以我不明白爲什麼currentPostId失敗,而this.currentPostId沒有。 – storedope

+0

'this.currentPostId'不會失敗,因爲沒有這樣的記錄要更新。嘗試使用'Posts.update({_ id:currentPostId},....)' – Xyand

回答

0

我看了看我的終端和因此出現了

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

的問題是一個被遺忘的警報();在Posts.deny();方法。從我現在警告的不是Javascript的一部分,而是DOM(?)。刪除警報()後,所有工作都應該如此。

在上面的代碼中的警報()(Posts.update();)工作,因爲它位於一個

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

因此,處理DOM事件,其中警報();工作得很好。

相關問題