我设法在前端显示了海报的用户 ID,并尝试了许多不同的方法来显示用户名而不是 ID。找不到什么问题或该做什么。
要发布的表格
<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 而不是用户名。
提前致谢!