[英]Meteor client side object update after server method using Angular-Meteor
I have a general question regarding Meteor and it's client side updates in combination with angular. 我对Meteor有一个一般性的问题,它是与angular结合的客户端更新。
Let's assume I am using meteors Accounts bundle and using the "users" collection filled with user objects (or any other collection, it doesn't matter). 假设我正在使用流星帐户捆绑包,并使用填充有用户对象的“用户”集合(或任何其他集合,都没有关系)。 Now I want to build a details page were I want to display the details of one user object. 现在,我想构建一个详细信息页面,以显示一个用户对象的详细信息。
On this page I am subscribing to the following publication: 在此页面上,我正在订阅以下出版物:
// server code
Meteor.publish('userDetails', function(userId) {
return Meteor.users.find({ _id: userId });
});
On the client side I am subscribing and loading the object like this: 在客户端,我正在订阅和加载这样的对象:
$scope.user = $scope.$meteorObject(Meteor.users, userId, false)
.subscribe('userDetails', userId);
On the details page is a button which triggers a meteor method which updates the currently displayed user object on the server side. 在详细信息页面上是一个按钮,该按钮触发流星方法,该方法更新服务器端当前显示的用户对象。 Something like this: 像这样:
Template: 模板:
// client template
<div>User object: {{user}}</div>
<button ng-click="modifyUser()">Do it!</button>
Controller: 控制器:
// client controller
...
$scope.modifyUser = function() {
$meteor.call('updateUser', $scope.user._id, 'foo').then(function(result) {
...
}, function(err) {
...
});
}
Server method: 服务器方法:
// server
Meteor.methods({
updateUser: function(userId, someValue) {
return Meteor.users.update({ _id: userId }, { $set: { 'profile.someValue': someValue }});
}
});
Now my question: 现在我的问题是:
What I am expecting is a automatic update of the user object after the updateUser
client side method call. 我期望的是在updateUser
客户端方法调用之后用户对象的自动更新。 But actually nothing is happening. 但是实际上什么也没发生。 What am I doing wrong? 我究竟做错了什么?
In general: How do I trigger a client side update of a model which was modified on the server in general? 一般来说:如何触发通常在服务器上修改过的模型的客户端更新? How can this be achieved when using Meteor-Angular? 使用Meteor-Angular时如何实现?
I found the reason for my problem: All of my Meteor.methods(...)
were defined only on the server-side. 我找到了问题的原因:我所有的Meteor.methods(...)
都仅在服务器端定义。 Now everything seems to work as expected. 现在一切似乎都按预期进行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.