Angular Meteor - 显示用户名而不是用户 ID
Angular Meteor - Displaying username instead of UserID
我设法在前端显示 poster 的用户 ID,我尝试了很多不同的方法来显示用户名而不是 ID。找不到问题所在或该怎么做。
表格为post
<form ng-show="$root.currentUser">
<label>Name</label>
<input ng-model="newPost.name">
<label>Description</label>
<input ng-model="newPost.description">
<button ng-click="newPost.owner=$root.currentUser._id; posts.push(newPost)">Add</button>
</form>
控制器
angular.module('posts').controller('PostsCtrl', ['$scope', '$meteor',
function($scope, $meteor){
$scope.posts = $meteor.collection(Posts);
$scope.remove = function(post){
$scope.posts.remove(post);
};
}]);
型号:
Posts = new Mongo.Collection("posts");
Posts.allow({
insert: function (userId, post) {
return userId && post.owner === userId;
},
update: function (userId, post, fields, modifier) {
return userId && post.owner === userId;
},
remove: function (userId, post) {
return userId && post.owner === userId;
}
});
编辑:
Html:
<p class="post-user">{{post.owner}}</p>
现在一切正常,但这次它显示的是用户 ID 而不是用户名。
提前致谢!
如果您认为其他所有内容都是正确的,请尝试以下操作:<p class="post-user">{{post.owner}}</p>
。正如我所说,我不知道流星,也许你的代码是正确的。但是当您添加 post 时,您将 owner
属性设置为用户名。我找不到你设置 newPost.username
.
的地方
如果向下滚动这一步,您可以找到 Meteor 的用户对象的默认结构:
http://angular-meteor.com/tutorial/step_09
您在哪里定义用户名?如果你不定义它,它就不会出现在任何地方。
通常用户信息保存在"profile"键下,但这取决于您使用的登录服务(Facebook,Email-Password)和您自己保存用户数据的实现。
我设法在前端显示 poster 的用户 ID,我尝试了很多不同的方法来显示用户名而不是 ID。找不到问题所在或该怎么做。
表格为post
<form ng-show="$root.currentUser">
<label>Name</label>
<input ng-model="newPost.name">
<label>Description</label>
<input ng-model="newPost.description">
<button ng-click="newPost.owner=$root.currentUser._id; posts.push(newPost)">Add</button>
</form>
控制器
angular.module('posts').controller('PostsCtrl', ['$scope', '$meteor',
function($scope, $meteor){
$scope.posts = $meteor.collection(Posts);
$scope.remove = function(post){
$scope.posts.remove(post);
};
}]);
型号:
Posts = new Mongo.Collection("posts");
Posts.allow({
insert: function (userId, post) {
return userId && post.owner === userId;
},
update: function (userId, post, fields, modifier) {
return userId && post.owner === userId;
},
remove: function (userId, post) {
return userId && post.owner === userId;
}
});
编辑: Html:
<p class="post-user">{{post.owner}}</p>
现在一切正常,但这次它显示的是用户 ID 而不是用户名。
提前致谢!
如果您认为其他所有内容都是正确的,请尝试以下操作:<p class="post-user">{{post.owner}}</p>
。正如我所说,我不知道流星,也许你的代码是正确的。但是当您添加 post 时,您将 owner
属性设置为用户名。我找不到你设置 newPost.username
.
如果向下滚动这一步,您可以找到 Meteor 的用户对象的默认结构: http://angular-meteor.com/tutorial/step_09
您在哪里定义用户名?如果你不定义它,它就不会出现在任何地方。 通常用户信息保存在"profile"键下,但这取决于您使用的登录服务(Facebook,Email-Password)和您自己保存用户数据的实现。