![](/img/trans.png)
[英]When update nested collection in meteor, how to pass variable for the update path
[英]How to update nested user collection
我已經嘗試了好一陣子了,感覺就像我已經嘗試了一切。
我在用戶下有一個稱為詳細信息的嵌套集合。 我沒有從客戶端更新明細字段的問題,但是為了安全起見,我顯然希望通過服務器運行更新。
這是我的服務器代碼:
//server code
Meteor.methods({
updateProfile : function() {
Meteor.users.update({ _id: Meteor.userId() }, { $set: { "details.phoneNumber" : phoneNumber }
});
}
});
和我的客戶代碼:
Template.userEdit.events({
'submit updateProfile' : function(e, t){
e.preventDefault();
var firstName = e.target.phoneNumber;
Meteor.call('phoneNumber');
}
});
目前,我正在發布/訂閱整個用戶集:
// Server
Meteor.publish("allUserData", function () {
return Meteor.users.find();
});
// Client
Tracker.autorun(function () {
Meteor.subscribe("allUserData");
});
您的服務器方法稱為“ updateProfile”,但在客戶端上稱為“ phoneNumber”。 在您的情況下,流星方法的調用方式如下:
Meteor.call("updateProfile", phoneNumber);
並且您的服務器方法必須接受一個參數作為輸入:
Meteor.methods({
updateProfile : function(phoneNumber) {
//...
}
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.